library(tidyverse)
## ── Attaching packages ──────────────────────────────────────────────────────────────────────────────────────── tidyverse 1.3.0 ──
## ✓ ggplot2 3.3.2     ✓ purrr   0.3.4
## ✓ tibble  3.0.3     ✓ dplyr   1.0.1
## ✓ tidyr   1.1.1     ✓ stringr 1.4.0
## ✓ readr   1.3.1     ✓ forcats 0.5.0
## ── Conflicts ─────────────────────────────────────────────────────────────────────────────────────────── tidyverse_conflicts() ──
## x dplyr::filter() masks stats::filter()
## x dplyr::lag()    masks stats::lag()
library(psych)
## 
## Attaching package: 'psych'
## The following objects are masked from 'package:ggplot2':
## 
##     %+%, alpha
library(patchwork)
library(rmatio)
library(reshape2)
## 
## Attaching package: 'reshape2'
## The following object is masked from 'package:tidyr':
## 
##     smiths
library(kableExtra)
## 
## Attaching package: 'kableExtra'
## The following object is masked from 'package:dplyr':
## 
##     group_rows
library(interactions)
library(readxl)
library(MASS)
## 
## Attaching package: 'MASS'
## The following object is masked from 'package:patchwork':
## 
##     area
## The following object is masked from 'package:dplyr':
## 
##     select
load("data/behav.RData")
load("data/load_effects_DFR.RData")
load("data/split_groups_info.RData")

source("helper_fxns/load_EEG_data.R")
source("helper_fxns/corr_spectrum_to_indiv_diff.R")
source("helper_fxns/mutate_for_heatmap.R")
source("helper_fxns/split_ERPs_into_groups.R")
source("helper_fxns/create_TC_for_plot.R")
source("helper_fxns/split_spectrum.R")
source("helper_fxns/paired_freq_plot.R")
source("helper_fxns/select_period_average.R")
source("helper_fxns/split_into_groups.R")
source("helper_fxns/prep_split_for_bar_plots.R")
source("helper_fxns/average_electrodes.R")
source("helper_fxns/average_electrodes_spectrum.R")
source("helper_fxns/plot_tertiles.R")
source("helper_fxns/find_inverted_U_spectra.R")
source("helper_fxns/time_sig_load_effects.R")
temp <- read.mat("data/EEG/DFR/ERPS_cl15_midOccip_reformatted.mat")
ERPS_times_DFR <- temp[["all_times"]]
temp <- read.mat("data/EEG/DFR/ERSPS_cl15_midOccip_reformatted.mat")
ERSPS_times_DFR <- temp[["all_times"]]
ERSPS_freqs <- temp[["all_freqs"]]


ERPS_midOccip_DFR <- load_EEG_data("DFR", "ERPS_cl15_midOccip")
ERSPS_midOccip_DFR <- load_EEG_data("DFR", "ERSPS_cl15_midOccip")
ERSPS_Oz_DFR <- load_EEG_data("DFR", "ERSPS_Oz")

ERPS_Pz_DFR <- load_EEG_data("DFR", "ERPS_Pz")
ERPS_P1_DFR <- load_EEG_data("DFR", "ERPS_P1")
ERPS_P2_DFR <- load_EEG_data("DFR", "ERPS_P2")
ERPS_CP1_DFR <- load_EEG_data("DFR", "ERPS_CP1")
ERPS_CP2_DFR <- load_EEG_data("DFR", "ERPS_CP2")
ERPS_POz_DFR <- load_EEG_data("DFR", "ERPS_POz")

ERSPS_Fz_DFR <- load_EEG_data("DFR", "ERSPS_Fz")
ERSPS_F1_DFR <- load_EEG_data("DFR", "ERSPS_F1")
ERSPS_F2_DFR <- load_EEG_data("DFR", "ERSPS_F2")
ERSPS_FC1_DFR <- load_EEG_data("DFR", "ERSPS_FC1")
ERSPS_FC2_DFR <- load_EEG_data("DFR", "ERSPS_FC2")
ERSPS_AFz_DFR <- load_EEG_data("DFR", "ERSPS_AFz")


ERPS_O1_DFR <- load_EEG_data("DFR", "ERPS_O1")
ERPS_O2_DFR <- load_EEG_data("DFR", "ERPS_O2")
ERPS_PO7_DFR <- load_EEG_data("DFR", "ERPS_PO7")
ERPS_PO8_DFR <- load_EEG_data("DFR", "ERPS_PO8")


ERPS_Oavg_DFR <- average_electrodes(list(ERPS_O1_DFR, ERPS_O2_DFR))
ERPS_POavg_DFR <- average_electrodes(list(ERPS_PO7_DFR, ERPS_PO8_DFR))

ERPS_Pavg_DFR <- average_electrodes(list(ERPS_Pz_DFR,ERPS_P1_DFR, ERPS_P2_DFR,ERPS_POz_DFR,ERPS_CP1_DFR, ERPS_CP2_DFR))
ERSPS_Favg_DFR <- average_electrodes_spectrum(list(ERSPS_Fz_DFR, ERSPS_F1_DFR, ERSPS_F2_DFR, ERSPS_AFz_DFR, ERSPS_FC1_DFR, ERSPS_FC2_DFR))

#save(list=c("CDA","CDA_fMRI","ERPS_times_DFR", "ERPS_times_LCD", "ERSPS_times_DFR", "ERSPS_times_LCD", "ERSPS_freqs", "ERPS_midOccip_LCD", "ERSPS_midOccip_LCD", "ERSPS_Oz_LCD","ERSPS_O2_LCD","ERSPS_O1_LCD", "ERPS_Pz_LCD","ERPS_Fz_LCD", "ERPS_midOccip_DFR", "ERSPS_midOccip_DFR", "ERSPS_Oz_DFR","ERPS_Pz_DFR"), file="data/newEEG_data.RData")

rects <- data.frame(xstart=c(0,5500),xend=c(2500,7000),col = "gray")

If we remove EEG from the span calculation, 10% of the subjects change their span group classification.

check_span_groups <- constructs_fMRI 

check_span_groups<- check_span_groups[order(check_span_groups$omnibus_span_no_DFR_MRI),]
check_span_groups$without_MRI <- "low"
check_span_groups$without_MRI[57] <- "not_incl"
check_span_groups$without_MRI[58:113] <- "med"
check_span_groups$without_MRI[114] <- "not_incl"
check_span_groups$without_MRI[115:170] <- "high"

check_span_groups<- check_span_groups[order(check_span_groups$omnibus_span_no_DFR),]
check_span_groups$without_EEG <- "low"
check_span_groups$without_EEG[57] <- "not_incl"
check_span_groups$without_EEG[58:113] <- "med"
check_span_groups$without_EEG[114] <- "not_incl"
check_span_groups$without_EEG[115:170] <- "high"

sum(check_span_groups$without_MRI != check_span_groups$without_EEG, na.rm=TRUE)
## [1] 17
check_span_groups <- merge(check_span_groups, p200_demographics)
colnames(check_span_groups)[10] <- "level"

WM_groups_no_EEG <- list(high = check_span_groups %>% filter(level == "high"),
                         med = check_span_groups %>% filter(level == "med"), 
                         low = check_span_groups %>% filter(level == "low"))

WM_groups_no_EEG[["all"]] <- rbind(WM_groups_no_EEG[["low"]],WM_groups_no_EEG[["med"]],WM_groups_no_EEG[["high"]] )

ERP Data

avg_ERPs_for_plot <- list(
  midOccip_DFR = data.frame(high_load = apply(ERPS_midOccip_DFR[["high_load"]][,2:1922], 2, mean),
                            low_load = apply(ERPS_midOccip_DFR[["low_load"]][,2:1922], 2, mean),
                            load_effect = apply(ERPS_midOccip_DFR[["load_effect"]][,2:1922], 2, mean),
                            time =ERPS_times_DFR),
  Pavg_DFR = data.frame(high_load = apply(ERPS_Pavg_DFR[["high_load"]][,2:1922], 2, mean),
                        low_load = apply(ERPS_Pavg_DFR[["low_load"]][,2:1922], 2, mean),
                        load_effect = apply(ERPS_Pavg_DFR[["load_effect"]][,2:1922], 2, mean),
                        time =ERPS_times_DFR),
  Oavg_DFR = data.frame(high_load = apply(ERPS_Oavg_DFR[["high_load"]][,2:1922], 2, mean),
                        low_load = apply(ERPS_Oavg_DFR[["low_load"]][,2:1922], 2, mean),
                        load_effect = apply(ERPS_Oavg_DFR[["load_effect"]][,2:1922], 2, mean),
                        time =ERPS_times_DFR), 
  POavg_DFR = data.frame(high_load = apply(ERPS_POavg_DFR[["high_load"]][,2:1922], 2, mean),
                         low_load = apply(ERPS_POavg_DFR[["low_load"]][,2:1922], 2, mean),
                         load_effect = apply(ERPS_POavg_DFR[["load_effect"]][,2:1922], 2, mean),
                         time =ERPS_times_DFR)
  
)
plot_list <- list()

for (cluster in seq.int(1,length(avg_ERPs_for_plot))){
  plot_list[[names(avg_ERPs_for_plot)[cluster]]][["indiv_loads"]] <- ggplot(data = avg_ERPs_for_plot[[cluster]])+
    geom_rect(data=rects,aes(xmin=xstart, xmax=xend, ymin = -Inf, ymax=Inf,alpha =0.005),fill="grey",show.legend = FALSE)+
    geom_line(aes(x=time,y=high_load))+
    geom_line(aes(x=time,y=low_load),linetype="dotted")+
    ylab("ERP")+
    ggtitle("Low Load vs High Load")+
    scale_x_continuous(breaks = seq(-500,7000, by = 1000))+
    theme_classic()
  
  plot_list[[names(avg_ERPs_for_plot)[cluster]]][["LE"]] <- ggplot(data = avg_ERPs_for_plot[[cluster]])+
    geom_line(aes(x=time,y=load_effect))+
    geom_rect(data=rects,aes(xmin=xstart, xmax=xend, ymin = -Inf, ymax=Inf,alpha =0.005),fill="grey",show.legend = FALSE)+
    ylab("ERP")+
    ggtitle("Load Effect")+
    scale_x_continuous(breaks = seq(-500,7000, by = 1000))+
    theme_classic()
  
}
avg_P <- (avg_ERPs_for_plot[["Pavg_DFR"]]$high_load + avg_ERPs_for_plot[["Pavg_DFR"]]$low_load)/2
avg_O <- (avg_ERPs_for_plot[["Oavg_DFR"]]$high_load + avg_ERPs_for_plot[["Oavg_DFR"]]$low_load)/2
avg_PO <- (avg_ERPs_for_plot[["POavg_DFR"]]$high_load + avg_ERPs_for_plot[["POavg_DFR"]]$low_load)/2

avg_plots <- data.frame(time = avg_ERPs_for_plot[["Pavg_DFR"]]$time, avg_P, avg_O, avg_PO)

ggplot(data = avg_plots)+
  geom_line(aes(x=time,y=avg_P))+
  geom_rect(data=rects,aes(xmin=xstart, xmax=xend, ymin = -Inf, ymax=Inf,alpha =0.005),fill="grey",show.legend = FALSE)+
  ylab("ERP")+
  ggtitle("Average P electrodes ERP")+
  scale_x_continuous(breaks = seq(-500,7000, by = 1000))+
  theme_classic()

ggplot(data = avg_plots)+
  geom_line(aes(x=time,y=avg_O))+
  geom_rect(data=rects,aes(xmin=xstart, xmax=xend, ymin = -Inf, ymax=Inf,alpha =0.005),fill="grey",show.legend = FALSE)+
  ylab("ERP")+
  ggtitle("Average O electrodes ERP")+
  scale_x_continuous(breaks = seq(-500,7000, by = 1000))+
  theme_classic()

ggplot(data = avg_plots)+
  geom_line(aes(x=time,y=avg_PO))+
  geom_rect(data=rects,aes(xmin=xstart, xmax=xend, ymin = -Inf, ymax=Inf,alpha =0.005),fill="grey",show.legend = FALSE)+
  ylab("ERP")+
  ggtitle("Average PO electrodes ERP")+
  scale_x_continuous(breaks = seq(-500,7000, by = 1000))+
  theme_classic()

cue_P3_range <- c(which(avg_plots$avg_P == max(avg_plots$avg_P[229:290]))-6 , which(avg_plots$avg_P == max(avg_plots$avg_P[229:290]))+6)


probe_P3_range <- c(which(avg_plots$avg_P == max(avg_plots$avg_P[1664:1680]))-6 , which(avg_plots$avg_P == max(avg_plots$avg_P[1664:1680]))+6)

cue_n170_range <- c(which(avg_plots$avg_O == min(avg_plots$avg_O[129:198]))-6, which(avg_plots$avg_O == min(avg_plots$avg_O[129:198]))+6)

probe_n170_range <- c(which(avg_plots$avg_O == min(avg_plots$avg_O[1550:1677]))-6,which(avg_plots$avg_O == min(avg_plots$avg_O[1550:1677]))+6)

All Subjects

During both the cue and probe, we see significant load effects in the N170 components in the average of the O1 and O2 electrodes and the PO7 and PO8 averages. We also see a load effect in the P3 in the parietal electrode average. Both of these show a larger amplitude in the low load than high load.

plot_list[["Pavg_DFR"]][["indiv_loads"]] + plot_list[["Pavg_DFR"]][["LE"]] +
  plot_annotation(title="P avg - DFR")

plot_list[["Oavg_DFR"]][["indiv_loads"]] + plot_list[["Oavg_DFR"]][["LE"]] +
  plot_annotation(title="O avg - DFR")

plot_list[["POavg_DFR"]][["indiv_loads"]] + plot_list[["POavg_DFR"]][["LE"]] +
  plot_annotation(title="PO avg - DFR")

cue_average_midOccip_n170 <- select_period_average(ERPS_midOccip_DFR,avg_plots$time[cue_n170_range[1]],avg_plots$time[cue_n170_range[2]],ERPS_times_DFR)
cue_average_O_n170 <- select_period_average(ERPS_Oavg_DFR,avg_plots$time[cue_n170_range[1]],avg_plots$time[cue_n170_range[2]],ERPS_times_DFR)
cue_average_PO_n170 <- select_period_average(ERPS_POavg_DFR,avg_plots$time[cue_n170_range[1]],avg_plots$time[cue_n170_range[2]],ERPS_times_DFR)

cue_average_P3 <- select_period_average(ERPS_Pavg_DFR,avg_plots$time[cue_P3_range[1]],avg_plots$time[cue_P3_range[2]],ERPS_times_DFR)

probe_average_midOccip_n170 <- select_period_average(ERPS_midOccip_DFR,avg_plots$time[probe_n170_range[1]],avg_plots$time[probe_n170_range[2]],ERPS_times_DFR)
probe_average_O_n170 <- select_period_average(ERPS_Oavg_DFR,avg_plots$time[probe_n170_range[1]],avg_plots$time[probe_n170_range[2]],ERPS_times_DFR)
probe_average_PO_n170 <- select_period_average(ERPS_POavg_DFR,avg_plots$time[probe_n170_range[1]],avg_plots$time[probe_n170_range[2]],ERPS_times_DFR)

probe_average_P3 <- select_period_average(ERPS_Pavg_DFR,avg_plots$time[probe_P3_range[1]],avg_plots$time[probe_P3_range[2]],ERPS_times_DFR)
t.test(cue_average_O_n170$load_effect,mu=0)
## 
##  One Sample t-test
## 
## data:  cue_average_O_n170$load_effect
## t = -5.2605, df = 189, p-value = 3.871e-07
## alternative hypothesis: true mean is not equal to 0
## 95 percent confidence interval:
##  -0.8283886 -0.3765553
## sample estimates:
## mean of x 
## -0.602472
t.test(cue_average_PO_n170$load_effect,mu=0)
## 
##  One Sample t-test
## 
## data:  cue_average_PO_n170$load_effect
## t = -6.9534, df = 189, p-value = 5.642e-11
## alternative hypothesis: true mean is not equal to 0
## 95 percent confidence interval:
##  -1.0704404 -0.5973194
## sample estimates:
##  mean of x 
## -0.8338799
t.test(cue_average_P3$load_effect,mu=0)
## 
##  One Sample t-test
## 
## data:  cue_average_P3$load_effect
## t = -5.1679, df = 189, p-value = 5.988e-07
## alternative hypothesis: true mean is not equal to 0
## 95 percent confidence interval:
##  -0.6709431 -0.3002420
## sample estimates:
##  mean of x 
## -0.4855926
t.test(probe_average_O_n170$load_effect,mu=0)
## 
##  One Sample t-test
## 
## data:  probe_average_O_n170$load_effect
## t = 0.24254, df = 189, p-value = 0.8086
## alternative hypothesis: true mean is not equal to 0
## 95 percent confidence interval:
##  -0.3504347  0.4486914
## sample estimates:
##  mean of x 
## 0.04912837
t.test(probe_average_PO_n170$load_effect,mu=0)
## 
##  One Sample t-test
## 
## data:  probe_average_PO_n170$load_effect
## t = -0.28819, df = 189, p-value = 0.7735
## alternative hypothesis: true mean is not equal to 0
## 95 percent confidence interval:
##  -0.8147653  0.6070440
## sample estimates:
##  mean of x 
## -0.1038607
t.test(probe_average_P3$load_effect,mu=0)
## 
##  One Sample t-test
## 
## data:  probe_average_P3$load_effect
## t = -4.9474, df = 189, p-value = 1.657e-06
## alternative hypothesis: true mean is not equal to 0
## 95 percent confidence interval:
##  -0.7978863 -0.3430026
## sample estimates:
##  mean of x 
## -0.5704444
split_ERPS_midOccip_DFR <- split_ERPs_into_groups(ERPS_midOccip_DFR, WM_groups_no_EEG, ERPS_times_DFR) 
split_ERPS_Pavg_DFR <- split_ERPs_into_groups(ERPS_Pavg_DFR, WM_groups_no_EEG, ERPS_times_DFR) 
split_ERPS_Oavg_DFR <- split_ERPs_into_groups(ERPS_Oavg_DFR, WM_groups_no_EEG, ERPS_times_DFR) 
split_ERPS_POavg_DFR <- split_ERPs_into_groups(ERPS_POavg_DFR, WM_groups_no_EEG, ERPS_times_DFR) 


ERPs_for_plot <- list(mid_Occip_DFR = split_ERPS_midOccip_DFR,
                      Pavg_DFR = split_ERPS_Pavg_DFR, 
                      Oavg_DFR = split_ERPS_Oavg_DFR, 
                      POavg_DFR = split_ERPS_POavg_DFR)
split_ERPs_plot <- create_TC_for_plot(ERPs_for_plot)

Split by WM groups

ggplot(data = split_ERPs_plot[["Pavg_DFR"]][["long"]])+
  geom_rect(data=rects,aes(xmin=xstart, xmax=xend, ymin = -Inf, ymax=Inf,alpha =0.005),fill="grey",show.legend = FALSE)+
  geom_line(data=split_ERPs_plot[["Pavg_DFR"]][["long"]] %>% filter(load=="high"),aes(x=Time,y=Mean,color=level)) +
  geom_line(data=split_ERPs_plot[["Pavg_DFR"]][["long"]] %>% filter(load=="low"),aes(x=Time,y=Mean,color=level),linetype="dotted")+
  scale_x_continuous(breaks = seq(-500,7000, by = 500))+
  ylab("Mean ERP")+
  ggtitle("P avg DFR")+
  theme_classic()

ggplot(data=split_ERPs_plot[["Pavg_DFR"]][["long"]])+
  geom_rect(data=rects,aes(xmin=xstart, xmax=xend, ymin = -Inf, ymax=Inf,alpha =0.005),fill="grey",show.legend = FALSE)+
  geom_line(data=split_ERPs_plot[["Pavg_DFR"]][["long"]] %>% filter(load=="load_effect"),aes(x=Time,y=Mean,color=level)) +
  ylab("Mean Activity") +
  xlab("Time (ms)")+
  geom_ribbon(data=split_ERPs_plot[["Pavg_DFR"]][["long"]] %>% filter(load == "load_effect") %>% filter(level=="high"),aes(x=Time,ymin=SE_min, ymax=SE_max),alpha=.2,linetype=2,fill="red")+
  geom_ribbon(data=split_ERPs_plot[["Pavg_DFR"]][["long"]] %>% filter(load == "load_effect") %>% filter(level=="med"),aes(x=Time,ymin=SE_min, ymax=SE_max),alpha=.2,linetype=2,fill="green")+
  geom_ribbon(data=split_ERPs_plot[["Pavg_DFR"]][["long"]] %>% filter(load == "load_effect") %>% filter(level=="low"),aes(x=Time,ymin=SE_min, ymax=SE_max),alpha=.2,linetype=2,fill="blue")+
  scale_x_continuous(breaks = seq(-500,7000, by = 500))+
  ylab("Mean ERP Load Effect")+
  ggtitle("P avg DFR")+
  theme_classic()

ggplot(data = split_ERPs_plot[["Oavg_DFR"]][["long"]])+
  geom_rect(data=rects,aes(xmin=xstart, xmax=xend, ymin = -Inf, ymax=Inf,alpha =0.005),fill="grey",show.legend = FALSE)+
  geom_line(data=split_ERPs_plot[["Oavg_DFR"]][["long"]] %>% filter(load=="high"),aes(x=Time,y=Mean,color=level)) +
  geom_line(data=split_ERPs_plot[["Oavg_DFR"]][["long"]] %>% filter(load=="low"),aes(x=Time,y=Mean,color=level),linetype="dotted")+
  scale_x_continuous(breaks = seq(-500,7000, by = 500))+
  ylab("Mean ERP")+
  ggtitle("O avg DFR")+
  theme_classic()

ggplot(data=split_ERPs_plot[["Oavg_DFR"]][["long"]])+
  geom_rect(data=rects,aes(xmin=xstart, xmax=xend, ymin = -Inf, ymax=Inf,alpha =0.005),fill="grey",show.legend = FALSE)+
  geom_line(data=split_ERPs_plot[["Oavg_DFR"]][["long"]] %>% filter(load=="load_effect"),aes(x=Time,y=Mean,color=level)) +
  ylab("Mean Activity") +
  xlab("Time (ms)")+
  geom_ribbon(data=split_ERPs_plot[["Oavg_DFR"]][["long"]] %>% filter(load == "load_effect") %>% filter(level=="high"),aes(x=Time,ymin=SE_min, ymax=SE_max),alpha=.2,linetype=2,fill="red")+
  geom_ribbon(data=split_ERPs_plot[["Oavg_DFR"]][["long"]] %>% filter(load == "load_effect") %>% filter(level=="med"),aes(x=Time,ymin=SE_min, ymax=SE_max),alpha=.2,linetype=2,fill="green")+
  geom_ribbon(data=split_ERPs_plot[["Oavg_DFR"]][["long"]] %>% filter(load == "load_effect") %>% filter(level=="low"),aes(x=Time,ymin=SE_min, ymax=SE_max),alpha=.2,linetype=2,fill="blue")+
  scale_x_continuous(breaks = seq(-500,7000, by = 500))+
  ylab("Mean ERP Load Effect")+
  ggtitle("O avg DFR")+
  theme_classic()

ggplot(data = split_ERPs_plot[["POavg_DFR"]][["long"]])+
  geom_rect(data=rects,aes(xmin=xstart, xmax=xend, ymin = -Inf, ymax=Inf,alpha =0.005),fill="grey",show.legend = FALSE)+
  geom_line(data=split_ERPs_plot[["POavg_DFR"]][["long"]] %>% filter(load=="high"),aes(x=Time,y=Mean,color=level)) +
  geom_line(data=split_ERPs_plot[["POavg_DFR"]][["long"]] %>% filter(load=="low"),aes(x=Time,y=Mean,color=level),linetype="dotted")+
  scale_x_continuous(breaks = seq(-500,7000, by = 500))+
  ylab("Mean ERP")+
  ggtitle("PO avg DFR")+
  theme_classic()

ggplot(data=split_ERPs_plot[["POavg_DFR"]][["long"]])+
  geom_rect(data=rects,aes(xmin=xstart, xmax=xend, ymin = -Inf, ymax=Inf,alpha =0.005),fill="grey",show.legend = FALSE)+
  geom_line(data=split_ERPs_plot[["POavg_DFR"]][["long"]] %>% filter(load=="load_effect"),aes(x=Time,y=Mean,color=level)) +
  ylab("Mean Activity") +
  xlab("Time (ms)")+
  geom_ribbon(data=split_ERPs_plot[["POavg_DFR"]][["long"]] %>% filter(load == "load_effect") %>% filter(level=="high"),aes(x=Time,ymin=SE_min, ymax=SE_max),alpha=.2,linetype=2,fill="red")+
  geom_ribbon(data=split_ERPs_plot[["POavg_DFR"]][["long"]] %>% filter(load == "load_effect") %>% filter(level=="med"),aes(x=Time,ymin=SE_min, ymax=SE_max),alpha=.2,linetype=2,fill="green")+
  geom_ribbon(data=split_ERPs_plot[["POavg_DFR"]][["long"]] %>% filter(load == "load_effect") %>% filter(level=="low"),aes(x=Time,ymin=SE_min, ymax=SE_max),alpha=.2,linetype=2,fill="blue")+
  scale_x_continuous(breaks = seq(-500,7000, by = 500))+
  ylab("Mean ERP Load Effect")+
  ggtitle("PO avg DFR")+
  theme_classic()

cue_P3_DFR_split <- split_into_groups(cue_average_P3, WM_groups_no_EEG)
cue_midOccip_n170_DFR_split <- split_into_groups(cue_average_midOccip_n170, WM_groups_no_EEG)
cue_Oavg_n170_DFR_split <- split_into_groups(cue_average_O_n170, WM_groups_no_EEG)
cue_POavg_n170_DFR_split <- split_into_groups(cue_average_PO_n170, WM_groups_no_EEG)


probe_P3_DFR_split <- split_into_groups(probe_average_P3, WM_groups_no_EEG)
probe_midOccip_n170_DFR_split <- split_into_groups(probe_average_midOccip_n170, WM_groups_no_EEG)
probe_Oavg_n170_DFR_split <- split_into_groups(probe_average_O_n170, WM_groups_no_EEG)
probe_POavg_n170_DFR_split <- split_into_groups(probe_average_PO_n170, WM_groups_no_EEG)


cue_P3_DFR_split_prepped <- prep_split_for_bar_plots(cue_P3_DFR_split)
cue_midOccip_n170_DFR_split_prepped <- prep_split_for_bar_plots(cue_midOccip_n170_DFR_split)
cue_Oavg_n170_DFR_split_prepped <- prep_split_for_bar_plots(cue_Oavg_n170_DFR_split)
cue_POavg_n170_DFR_split_prepped <- prep_split_for_bar_plots(cue_POavg_n170_DFR_split)


probe_P3_DFR_split_prepped <- prep_split_for_bar_plots(probe_P3_DFR_split)
probe_midOccip_n170_DFR_split_prepped <- prep_split_for_bar_plots(probe_midOccip_n170_DFR_split)
probe_Oavg_n170_DFR_split_prepped <- prep_split_for_bar_plots(probe_Oavg_n170_DFR_split)
probe_POavg_n170_DFR_split_prepped <- prep_split_for_bar_plots(probe_POavg_n170_DFR_split)
WM_to_merge <- WM_groups_no_EEG[["all"]][,c(1,10)]

cue_midOccip_n170_DFR_anova <- merge(cue_average_midOccip_n170,WM_to_merge, by="PTID")
probe_midOccip_n170_DFR_anova <- merge(probe_average_midOccip_n170,WM_to_merge, by="PTID")

cue_Oavg_n170_DFR_anova <- merge(cue_average_O_n170,WM_to_merge, by="PTID")
probe_Oavg_n170_DFR_anova <- merge(probe_average_O_n170,WM_to_merge, by="PTID")

cue_POavg_n170_DFR_anova <- merge(cue_average_PO_n170,WM_to_merge, by="PTID")
probe_POavg_n170_DFR_anova <- merge(probe_average_PO_n170,WM_to_merge, by="PTID")

cue_P3_DFR_anova <- merge(cue_average_P3,WM_to_merge, by="PTID")
probe_P3_DFR_anova <- merge(probe_average_P3,WM_to_merge, by="PTID")

Load Effect

Scatter plots

Here, we want to look to see uf there are any obvious relationships between span and ERP measures (removing any outliers) for the load effects, but there is a significant linear relationship between P3 during cue at high load and omnibus span. We don’t see anything really strong for the load effects.

merge(cue_midOccip_n170_DFR_anova, constructs_fMRI) %>% 
  filter(high_load < mean(high_load)+3*(sd(high_load))) %>%
  filter(high_load > mean(high_load)-3*(sd(high_load))) %>%
  ggplot(aes(x=omnibus_span_no_DFR, y = high_load)) +
  geom_point()+
  stat_smooth(method="lm")+ 
  ylab("high load - cue n170 in midOccip")+
  theme_classic()
## `geom_smooth()` using formula 'y ~ x'

summary(cue_midOccip_n170 <- MASS::rlm(high_load ~ omnibus_span_no_DFR, data = merge(cue_midOccip_n170_DFR_anova, constructs_fMRI)))
## 
## Call: rlm(formula = high_load ~ omnibus_span_no_DFR, data = merge(cue_midOccip_n170_DFR_anova, 
##     constructs_fMRI))
## Residuals:
##       Min        1Q    Median        3Q       Max 
## -2.733837 -0.356895 -0.003818  0.408339  4.001661 
## 
## Coefficients:
##                     Value  Std. Error t value
## (Intercept)         0.1723 0.0553     3.1186 
## omnibus_span_no_DFR 0.1284 0.0946     1.3571 
## 
## Residual standard error: 0.5376 on 149 degrees of freedom
merge(cue_Oavg_n170_DFR_anova, constructs_fMRI) %>% 
  filter(high_load < mean(high_load)+3*(sd(high_load))) %>%
  filter(high_load > mean(high_load)-3*(sd(high_load))) %>%
  ggplot(aes(x=omnibus_span_no_DFR, y = high_load)) +
  geom_point()+
  stat_smooth(method="lm")+ 
  ylab("high load - cue Oavg in midOccip")+
  theme_classic()
## `geom_smooth()` using formula 'y ~ x'

summary(cue_Oavg_n170 <- MASS::rlm(high_load ~ omnibus_span_no_DFR, data = merge(cue_Oavg_n170_DFR_anova, constructs_fMRI)))
## 
## Call: rlm(formula = high_load ~ omnibus_span_no_DFR, data = merge(cue_Oavg_n170_DFR_anova, 
##     constructs_fMRI))
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -9.3243 -2.4653 -0.1323  2.4126 10.3318 
## 
## Coefficients:
##                     Value  Std. Error t value
## (Intercept)         1.0003 0.2945     3.3961 
## omnibus_span_no_DFR 0.8539 0.5066     1.6855 
## 
## Residual standard error: 3.607 on 159 degrees of freedom
merge(cue_P3_DFR_anova, constructs_fMRI) %>% 
  filter(high_load < mean(high_load)+3*(sd(high_load))) %>%
  filter(high_load > mean(high_load)-3*(sd(high_load))) %>%
  ggplot(aes(x=omnibus_span_no_DFR, y = high_load)) +
  geom_point()+
  stat_smooth(method="lm")+ 
  ylab("high load - cue P3")+
  theme_classic()
## `geom_smooth()` using formula 'y ~ x'

summary(cue_P3 <- MASS::rlm(high_load ~ omnibus_span_no_DFR, data = merge(cue_P3_DFR_anova, constructs_fMRI)))
## 
## Call: rlm(formula = high_load ~ omnibus_span_no_DFR, data = merge(cue_P3_DFR_anova, 
##     constructs_fMRI))
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -5.4454 -1.2291  0.1479  1.0371  5.4934 
## 
## Coefficients:
##                     Value   Std. Error t value
## (Intercept)          3.3017  0.1517    21.7632
## omnibus_span_no_DFR  1.2225  0.2610     4.6845
## 
## Residual standard error: 1.742 on 159 degrees of freedom
merge(cue_midOccip_n170_DFR_anova, constructs_fMRI) %>% 
  filter(load_effect < mean(load_effect)+3*(sd(load_effect))) %>%
  filter(load_effect > mean(load_effect)-3*(sd(load_effect))) %>%
  ggplot(aes(x=omnibus_span_no_DFR, y = load_effect)) +
  geom_point()+
  stat_smooth(method="lm")+ 
  ylab("Load effect - cue n170 in midOccip")+
  theme_classic()
## `geom_smooth()` using formula 'y ~ x'

merge(probe_midOccip_n170_DFR_anova, constructs_fMRI) %>% 
  filter(load_effect < mean(load_effect)+3*(sd(load_effect))) %>%
  filter(load_effect > mean(load_effect)-3*(sd(load_effect))) %>%
  ggplot(aes(x=omnibus_span_no_DFR, y = load_effect)) +
  geom_point()+
  stat_smooth(method="lm")+ 
  ylab("Load effect - probe n170 in midOccip")+
  theme_classic()
## `geom_smooth()` using formula 'y ~ x'

merge(cue_Oavg_n170_DFR_anova, constructs_fMRI) %>% 
  filter(load_effect < mean(load_effect)+3*(sd(load_effect))) %>%
  filter(load_effect > mean(load_effect)-3*(sd(load_effect))) %>%
  ggplot(aes(x=omnibus_span_no_DFR, y = load_effect)) +
  geom_point()+
  stat_smooth(method="lm")+ 
  ylab("Load effect - cue Oavg in midOccip")+
  theme_classic()
## `geom_smooth()` using formula 'y ~ x'

merge(probe_Oavg_n170_DFR_anova, constructs_fMRI) %>% 
  filter(load_effect < mean(load_effect)+3*(sd(load_effect))) %>%
  filter(load_effect > mean(load_effect)-3*(sd(load_effect))) %>%
  ggplot(aes(x=omnibus_span_no_DFR, y = load_effect)) +
  geom_point()+
  stat_smooth(method="lm")+ 
  ylab("Load effect - probe Oavg in midOccip")+
  theme_classic()
## `geom_smooth()` using formula 'y ~ x'

merge(cue_P3_DFR_anova, constructs_fMRI) %>% 
  filter(load_effect < mean(load_effect)+3*(sd(load_effect))) %>%
  filter(load_effect > mean(load_effect)-3*(sd(load_effect))) %>%
  ggplot(aes(x=omnibus_span_no_DFR, y = load_effect)) +
  geom_point()+
  stat_smooth(method="lm")+ 
  ylab("Load effect - cue P3")+
  theme_classic()
## `geom_smooth()` using formula 'y ~ x'

merge(probe_P3_DFR_anova, constructs_fMRI) %>% 
  filter(load_effect < mean(load_effect)+3*(sd(load_effect))) %>%
  filter(load_effect > mean(load_effect)-3*(sd(load_effect))) %>%  
  ggplot(aes(x=omnibus_span_no_DFR, y = load_effect)) +
  geom_point()+
  stat_smooth(method="lm")+ 
  ylab("Load effect - probe P3")+
  theme_classic()
## `geom_smooth()` using formula 'y ~ x'

Bar Graphs

When we plot bar graphs, we don’t see any difference between load effects

cue_P3_DFR_split_prepped[["melt_data"]] %>% 
  filter(variable=="load_effect") %>% 
  mutate(level = factor(level, levels =c("low","med","high"))) %>%
  ggplot()+
  geom_bar(aes(x=level,y=Means),stat="identity")+
  geom_errorbar(aes(x=level,ymin=Means-SE, ymax=Means+SE), width=0.2)+
  ggtitle("Cue")+ 
  xlab("WMC")+
  ylab("ERP amplitude")+
  theme_classic()+
  theme(aspect.ratio = 1) -> cue_P3_LE

cue_midOccip_n170_DFR_split_prepped[["melt_data"]] %>% 
  filter(variable=="load_effect") %>% 
  mutate(level = factor(level, levels =c("low","med","high"))) %>%
  ggplot()+
  geom_bar(aes(x=level,y=Means),stat="identity")+
  geom_errorbar(aes(x=level,ymin=Means-SE, ymax=Means+SE), width=0.2)+
  ggtitle("Cue")+ 
  xlab("WMC")+
  ylab("ERP amplitude")+
  theme_classic()+
  theme(aspect.ratio = 1) -> cue_midOccip_n170_LE


cue_Oavg_n170_DFR_split_prepped[["melt_data"]] %>% 
  filter(variable=="load_effect") %>% 
  mutate(level = factor(level, levels =c("low","med","high"))) %>%
  ggplot()+
  geom_bar(aes(x=level,y=Means),stat="identity")+
  geom_errorbar(aes(x=level,ymin=Means-SE, ymax=Means+SE), width=0.2)+
  ggtitle("Cue")+ 
  xlab("WMC")+
  ylab("ERP amplitude")+
  theme_classic()+
  theme(aspect.ratio = 1) -> cue_Oavg_n170_LE

cue_POavg_n170_DFR_split_prepped[["melt_data"]] %>% 
  filter(variable=="load_effect") %>% 
  mutate(level = factor(level, levels =c("low","med","high"))) %>%
  ggplot()+
  geom_bar(aes(x=level,y=Means),stat="identity")+
  geom_errorbar(aes(x=level,ymin=Means-SE, ymax=Means+SE), width=0.2)+
  ggtitle("Cue")+ 
  xlab("WMC")+
  ylab("ERP amplitude")+
  theme_classic()+
  theme(aspect.ratio = 1) -> cue_POavg_n170_LE

probe_P3_DFR_split_prepped[["melt_data"]] %>% 
  filter(variable=="load_effect") %>% 
  mutate(level = factor(level, levels =c("low","med","high"))) %>%
  ggplot()+
  geom_bar(aes(x=level,y=Means),stat="identity")+
  geom_errorbar(aes(x=level,ymin=Means-SE, ymax=Means+SE), width=0.2)+
  ggtitle("Probe")+ 
  xlab("WMC")+
  ylab("ERP amplitude")+
  theme_classic()+
  theme(aspect.ratio = 1) -> probe_P3_LE

probe_midOccip_n170_DFR_split_prepped[["melt_data"]] %>% 
  filter(variable=="load_effect") %>% 
  mutate(level = factor(level, levels =c("low","med","high"))) %>%
  ggplot()+
  geom_bar(aes(x=level,y=Means),stat="identity")+
  geom_errorbar(aes(x=level,ymin=Means-SE, ymax=Means+SE), width=0.2)+
  ggtitle("Probe")+ 
  xlab("WMC")+
  ylab("ERP amplitude")+
  theme_classic()+
  theme(aspect.ratio = 1) -> probe_midOccip_n170_LE

probe_Oavg_n170_DFR_split_prepped[["melt_data"]] %>% 
  filter(variable=="load_effect") %>% 
  mutate(level = factor(level, levels =c("low","med","high"))) %>%
  ggplot()+
  geom_bar(aes(x=level,y=Means),stat="identity")+
  geom_errorbar(aes(x=level,ymin=Means-SE, ymax=Means+SE), width=0.2)+
  ggtitle("Probe")+ 
  xlab("WMC")+
  ylab("ERP amplitude")+
  theme_classic()+
  theme(aspect.ratio = 1) -> probe_Oavg_n170_LE

probe_POavg_n170_DFR_split_prepped[["melt_data"]] %>% 
  filter(variable=="load_effect") %>% 
  mutate(level = factor(level, levels =c("low","med","high"))) %>%
  ggplot()+
  geom_bar(aes(x=level,y=Means),stat="identity")+
  geom_errorbar(aes(x=level,ymin=Means-SE, ymax=Means+SE), width=0.2)+
  ggtitle("Probe")+ 
  xlab("WMC")+
  ylab("ERP amplitude")+
  theme_classic()+
  theme(aspect.ratio = 1) -> probe_POavg_n170_LE

cue_P3_LE + probe_P3_LE+
  plot_annotation(title="P3 Load Effect during DFR")

cue_Oavg_n170_LE + probe_Oavg_n170_LE+
  plot_annotation(title="Oavg n170 Load Effect during DFR")

cue_POavg_n170_LE + probe_POavg_n170_LE+
  plot_annotation(title="POavg n170 Load Effect during DFR")

For the n170 in the cue period, low and high capacity groups are significantly different from 0, but medium capacity are not. In the probe period, no groups are significantly different from 0.

For the P3 in the cue period, all groups are significantly different from 0. In the probe, medium WMC subjects are significantly different.

t_test_cue_O_n170 <- cue_Oavg_n170_DFR_anova %>% 
  data.frame() %>%
  group_by(level) %>% 
  summarise(name = unique(level), res = list(t.test(load_effect,mu=0)))
## `summarise()` ungrouping output (override with `.groups` argument)
names(t_test_cue_O_n170$res) <- unique(t_test_cue_O_n170$name)
t_test_cue_O_n170$res
## $high
## 
##  One Sample t-test
## 
## data:  load_effect
## t = -2.19, df = 54, p-value = 0.03286
## alternative hypothesis: true mean is not equal to 0
## 95 percent confidence interval:
##  -0.92463390 -0.04081225
## sample estimates:
##  mean of x 
## -0.4827231 
## 
## 
## $low
## 
##  One Sample t-test
## 
## data:  load_effect
## t = -3.8483, df = 51, p-value = 0.0003325
## alternative hypothesis: true mean is not equal to 0
## 95 percent confidence interval:
##  -1.1191636 -0.3517934
## sample estimates:
##  mean of x 
## -0.7354785 
## 
## 
## $med
## 
##  One Sample t-test
## 
## data:  load_effect
## t = -1.8146, df = 53, p-value = 0.07525
## alternative hypothesis: true mean is not equal to 0
## 95 percent confidence interval:
##  -0.86059437  0.04306837
## sample estimates:
## mean of x 
## -0.408763
t_test_probe_O_n170 <- probe_Oavg_n170_DFR_anova %>% 
  data.frame() %>%
  group_by(level) %>% 
  summarise(name = unique(level), res = list(t.test(load_effect,mu=0)))
## `summarise()` ungrouping output (override with `.groups` argument)
names(t_test_probe_O_n170$res) <- unique(t_test_probe_O_n170$name)
t_test_probe_O_n170$res
## $high
## 
##  One Sample t-test
## 
## data:  load_effect
## t = 0.41506, df = 54, p-value = 0.6797
## alternative hypothesis: true mean is not equal to 0
## 95 percent confidence interval:
##  -0.9557956  1.4548566
## sample estimates:
## mean of x 
## 0.2495305 
## 
## 
## $low
## 
##  One Sample t-test
## 
## data:  load_effect
## t = 0.049195, df = 51, p-value = 0.961
## alternative hypothesis: true mean is not equal to 0
## 95 percent confidence interval:
##  -0.5433795  0.5706788
## sample estimates:
##  mean of x 
## 0.01364963 
## 
## 
## $med
## 
##  One Sample t-test
## 
## data:  load_effect
## t = -0.066358, df = 53, p-value = 0.9473
## alternative hypothesis: true mean is not equal to 0
## 95 percent confidence interval:
##  -0.4571914  0.4279088
## sample estimates:
##   mean of x 
## -0.01464127
t_test_cue_P3 <- cue_P3_DFR_anova %>% 
  data.frame() %>%
  group_by(level) %>% 
  summarise(name = unique(level), res = list(t.test(load_effect,mu=0)))
## `summarise()` ungrouping output (override with `.groups` argument)
names(t_test_cue_P3$res) <- unique(t_test_cue_P3$name)
t_test_cue_P3$res
## $high
## 
##  One Sample t-test
## 
## data:  load_effect
## t = -2.7646, df = 54, p-value = 0.007782
## alternative hypothesis: true mean is not equal to 0
## 95 percent confidence interval:
##  -0.9148368 -0.1457156
## sample estimates:
##  mean of x 
## -0.5302762 
## 
## 
## $low
## 
##  One Sample t-test
## 
## data:  load_effect
## t = -2.799, df = 51, p-value = 0.007218
## alternative hypothesis: true mean is not equal to 0
## 95 percent confidence interval:
##  -0.6971910 -0.1147995
## sample estimates:
##  mean of x 
## -0.4059953 
## 
## 
## $med
## 
##  One Sample t-test
## 
## data:  load_effect
## t = -2.5241, df = 53, p-value = 0.01463
## alternative hypothesis: true mean is not equal to 0
## 95 percent confidence interval:
##  -0.8898522 -0.1018298
## sample estimates:
## mean of x 
## -0.495841
t_test_probe_P3 <- probe_P3_DFR_anova %>% 
  data.frame() %>%
  group_by(level) %>% 
  summarise(name = unique(level), res = list(t.test(load_effect,mu=0)))
## `summarise()` ungrouping output (override with `.groups` argument)
names(t_test_probe_P3$res) <- unique(t_test_probe_P3$name)
t_test_probe_P3$res
## $high
## 
##  One Sample t-test
## 
## data:  load_effect
## t = -1.8505, df = 54, p-value = 0.06971
## alternative hypothesis: true mean is not equal to 0
## 95 percent confidence interval:
##  -1.097236  0.043928
## sample estimates:
##  mean of x 
## -0.5266543 
## 
## 
## $low
## 
##  One Sample t-test
## 
## data:  load_effect
## t = -1.9751, df = 51, p-value = 0.05368
## alternative hypothesis: true mean is not equal to 0
## 95 percent confidence interval:
##  -0.841447824  0.006857664
## sample estimates:
##  mean of x 
## -0.4172951 
## 
## 
## $med
## 
##  One Sample t-test
## 
## data:  load_effect
## t = -3.5704, df = 53, p-value = 0.0007675
## alternative hypothesis: true mean is not equal to 0
## 95 percent confidence interval:
##  -0.8822698 -0.2475663
## sample estimates:
## mean of x 
## -0.564918
cue_Oavg_n170_LE.aov <- aov(load_effect ~ level, data = cue_Oavg_n170_DFR_anova)
print(summary(cue_Oavg_n170_LE.aov))
##              Df Sum Sq Mean Sq F value Pr(>F)
## level         2    3.1   1.549   0.633  0.532
## Residuals   158  386.4   2.446
probe_Oavg_n170_LE.aov <- aov(load_effect ~ level, data = probe_Oavg_n170_DFR_anova)
print(summary(probe_Oavg_n170_LE.aov))
##              Df Sum Sq Mean Sq F value Pr(>F)
## level         2    2.3   1.145   0.128   0.88
## Residuals   158 1417.0   8.968
cue_POavg_n170_LE.aov <- aov(load_effect ~ level, data = cue_POavg_n170_DFR_anova)
print(summary(cue_POavg_n170_LE.aov))
##              Df Sum Sq Mean Sq F value Pr(>F)
## level         2    2.8   1.411   0.518  0.597
## Residuals   158  430.3   2.723
probe_POavg_n170_LE.aov <- aov(load_effect ~ level, data = probe_POavg_n170_DFR_anova)
print(summary(probe_POavg_n170_LE.aov))
##              Df Sum Sq Mean Sq F value Pr(>F)
## level         2     40   19.95    0.69  0.503
## Residuals   158   4573   28.94
cue_P3_LE.aov <- aov(load_effect ~ level, data = cue_P3_DFR_anova)
print(summary(cue_P3_LE.aov))
##              Df Sum Sq Mean Sq F value Pr(>F)
## level         2   0.44  0.2185   0.125  0.882
## Residuals   158 275.51  1.7437
probe_P3_LE.aov <- aov(load_effect ~ level, data = probe_P3_DFR_anova)
print(summary(probe_P3_LE.aov))
##              Df Sum Sq Mean Sq F value Pr(>F)
## level         2    0.6  0.3098   0.114  0.893
## Residuals   158  430.6  2.7252

ERSPs

temp_diff <- constructs_fMRI[,c(1,8)]

omnibus_span_corr <- list(
  ERSPS_midOccip_DFR = corr_spectrum_to_indiv_diff(indiv_diff = temp_diff, spectrum = ERSPS_midOccip_DFR[["data"]][["load_effect"]], spec_PTID = ERSPS_midOccip_DFR[["PTID"]], times=ERSPS_times_DFR),
  ERSPS_Oz_DFR = corr_spectrum_to_indiv_diff(indiv_diff = temp_diff, spectrum = ERSPS_Oz_DFR[["data"]][["load_effect"]], spec_PTID = ERSPS_Oz_DFR[["PTID"]], times=ERSPS_times_DFR), 
  
  ERSPS_Favg_DFR = corr_spectrum_to_indiv_diff(indiv_diff = temp_diff, spectrum = ERSPS_Favg_DFR[["data"]][["load_effect"]], spec_PTID = ERSPS_Favg_DFR[["PTID"]], times=ERSPS_times_DFR) 
)
## Warning: The `x` argument of `as_tibble.matrix()` must have unique column names if `.name_repair` is omitted as of tibble 2.0.0.
## Using compatibility `.name_repair`.
## This warning is displayed once every 8 hours.
## Call `lifecycle::last_warnings()` to see where this warning was generated.
temp_diff <- constructs_fMRI[,c(1,8)]
temp_diff[,2] <- temp_diff[,2]^2
colnames(temp_diff)[2] <- "span_squared"

omnibus_span_squared_corr <- list(
  ERSPS_midOccip_DFR = corr_spectrum_to_indiv_diff(indiv_diff = temp_diff, spectrum = ERSPS_midOccip_DFR[["data"]][["load_effect"]], spec_PTID = ERSPS_midOccip_DFR[["PTID"]], times=ERSPS_times_DFR),
  ERSPS_Oz_DFR = corr_spectrum_to_indiv_diff(indiv_diff = temp_diff, spectrum = ERSPS_Oz_DFR[["data"]][["load_effect"]], spec_PTID = ERSPS_Oz_DFR[["PTID"]], times=ERSPS_times_DFR), 
  
  ERSPS_Favg_DFR = corr_spectrum_to_indiv_diff(indiv_diff = temp_diff, spectrum = ERSPS_Favg_DFR[["data"]][["load_effect"]], spec_PTID = ERSPS_Favg_DFR[["PTID"]], times=ERSPS_times_DFR) 
)
temp_diff <- data.frame(p200_data[p200_data$PTID %in% constructs_fMRI$PTID, c(1,7)])

DFR_L3_acc_corr <- list(
  ERSPS_midOccip_DFR = corr_spectrum_to_indiv_diff(indiv_diff = temp_diff, spectrum = ERSPS_midOccip_DFR[["data"]][["load_effect"]], spec_PTID = ERSPS_midOccip_DFR[["PTID"]], times=ERSPS_times_DFR),
  ERSPS_Oz_DFR = corr_spectrum_to_indiv_diff(indiv_diff = temp_diff, spectrum = ERSPS_Oz_DFR[["data"]][["load_effect"]], spec_PTID = ERSPS_Oz_DFR[["PTID"]], times=ERSPS_times_DFR), 
  
  ERSPS_Favg_DFR = corr_spectrum_to_indiv_diff(indiv_diff = temp_diff, spectrum = ERSPS_Favg_DFR[["data"]][["load_effect"]], spec_PTID = ERSPS_Favg_DFR[["PTID"]], times=ERSPS_times_DFR) 
)
temp_diff <- data.frame(PTID=constructs_fMRI$PTID, LE = p200_delay_DFR$DFR_Load3_Load1)

DFR_fMRI_LE_corr <- list(
  ERSPS_midOccip_DFR = corr_spectrum_to_indiv_diff(indiv_diff = temp_diff, spectrum = ERSPS_midOccip_DFR[["data"]][["load_effect"]], spec_PTID = ERSPS_midOccip_DFR[["PTID"]], times=ERSPS_times_DFR),
  ERSPS_Oz_DFR = corr_spectrum_to_indiv_diff(indiv_diff = temp_diff, spectrum = ERSPS_Oz_DFR[["data"]][["load_effect"]], spec_PTID = ERSPS_Oz_DFR[["PTID"]], times=ERSPS_times_DFR), 
  
  ERSPS_Favg_DFR = corr_spectrum_to_indiv_diff(indiv_diff = temp_diff, spectrum = ERSPS_Favg_DFR[["data"]][["load_effect"]], spec_PTID = ERSPS_Favg_DFR[["PTID"]], times=ERSPS_times_DFR) 
)

Average over all subs

avg_ERSPS_midOccip_DFR <- mutate_for_heatmap(apply(ERSPS_midOccip_DFR[["data"]][["load_effect"]],c(1,2),mean))
avg_ERSPS_Oz_DFR <- mutate_for_heatmap(apply(ERSPS_Oz_DFR[["data"]][["load_effect"]],c(1,2),mean))
avg_ERSPS_Favg_DFR <- mutate_for_heatmap(apply(ERSPS_Favg_DFR[["data"]][["load_effect"]],c(1,2),mean))


ggplot(data=avg_ERSPS_midOccip_DFR, aes(x=Y,y=X,fill=Z))+
  geom_tile()+
  ggtitle("midOccip cluster during DFR")+
  scale_y_continuous(labels = function(x){return(round(ERSPS_freqs[x+1], digits=2))},breaks = seq(0, 76, by = 5))+
  scale_x_continuous(labels = function(x){return(ERSPS_times_DFR[x+1])}, breaks = seq(0,150, by = 25))+
  scale_fill_gradient2(limits=c(-1.8, 1.25),breaks=seq.int(-1.5,1,0.5),low="blue",mid="white",high="red") +
  xlab("Time (ms)")+
  ylab("Frequency")+
  labs(fill="Power Load Effect")+
  theme_classic()

ggplot(data=avg_ERSPS_Oz_DFR, aes(x=Y,y=X,fill=Z))+
  geom_tile()+
  ggtitle("Oz electrode during DFR")+
  scale_y_continuous(labels = function(x){return(round(ERSPS_freqs[x+1], digits=2))},breaks = seq(0, 76, by = 5))+
  scale_x_continuous(labels = function(x){return(ERSPS_times_DFR[x+1])}, breaks = seq(0,150, by = 25))+
  scale_fill_gradient2(limits=c(-1.8, 1.25),breaks=seq.int(-1.5,1,0.5),low="blue",mid="white",high="red") +
  xlab("Time (ms)")+
  ylab("Frequency")+
  labs(fill="Power Load Effect")+
  theme_classic()

Split by WMC

These plots give a good overview, but we will inspect each of the frequency bands more in depth later.

split_ERSPS_midOccip_DFR <- split_spectrum(ERSPS_midOccip_DFR, WM_groups_no_EEG)
split_ERSPS_Oz_DFR <- split_spectrum(ERSPS_Oz_DFR, WM_groups_no_EEG)
split_ERSPS_Favg_DFR <- split_spectrum(ERSPS_Favg_DFR, WM_groups_no_EEG)
split_ERSPS_midOccip_DFR_for_plot <- list()
split_ERSPS_Oz_DFR_for_plot <- list()
split_ERSPS_Favg_DFR_for_plot <- list()

split_ERSPS_midOccip_DFR_plots <- list()
split_ERSPS_Oz_DFR_plots <- list()
split_ERSPS_Favg_DFR_plots <- list()


for (group in c("high","med","low")){
  split_ERSPS_midOccip_DFR_for_plot[[group]] <- mutate_for_heatmap(split_ERSPS_midOccip_DFR[[group]][["load_effect"]])
  split_ERSPS_Oz_DFR_for_plot[[group]] <- mutate_for_heatmap(split_ERSPS_Oz_DFR[[group]][["load_effect"]])
  split_ERSPS_Favg_DFR_for_plot[[group]] <- mutate_for_heatmap(split_ERSPS_Favg_DFR[[group]][["load_effect"]])
  
  
  
  
  split_ERSPS_midOccip_DFR_plots[[group]] <- ggplot(data=split_ERSPS_midOccip_DFR_for_plot[[group]], aes(x=Y,y=X,fill=Z))+
    geom_tile()+
    ggtitle(paste0(group, " WMC in midOccip during DFR"))+
    geom_vline(linetype = "dotted",xintercept = 11)+
    geom_vline(linetype = "dotted", xintercept = 61)+
    geom_vline(linetype= "dotted", xintercept = 122)+
    scale_y_continuous(labels = function(x){return(round(ERSPS_freqs[x+1], digits=2))},breaks = seq(0, 76, by = 5))+
    scale_x_continuous(labels = function(x){return(ERSPS_times_DFR[x+1])}, breaks = seq(0,150, by = 25))+
    scale_fill_gradient2(limits=c(-2.5, 1.75),breaks=seq.int(-2,1.5,1),low="blue",mid="white",high="red") +
    xlab("Time (ms)")+
    ylab("Frequency")+
    labs(fill="Power Load Effect")+
    theme_classic()
  
  split_ERSPS_Oz_DFR_plots[[group]] <- ggplot(data=split_ERSPS_Oz_DFR_for_plot[[group]], aes(x=Y,y=X,fill=Z))+
    geom_tile()+
    ggtitle(paste0(group, " WMC in Oz during DFR"))+
    geom_vline(linetype = "dotted",xintercept = 11)+
    geom_vline(linetype = "dotted", xintercept = 61)+
    geom_vline(linetype= "dotted", xintercept = 122)+
    scale_y_continuous(labels = function(x){return(round(ERSPS_freqs[x+1], digits=2))},breaks = seq(0, 76, by = 5))+
    scale_x_continuous(labels = function(x){return(ERSPS_times_DFR[x+1])}, breaks = seq(0,150, by = 25))+
    scale_fill_gradient2(limits=c(-2.5, 1.75),breaks=seq.int(-2,1.5,1),low="blue",mid="white",high="red") +
    xlab("Time (ms)")+
    ylab("Frequency")+
    labs(fill="Power Load Effect")+
    theme_classic() 
  
  split_ERSPS_Favg_DFR_plots[[group]] <- ggplot(data=split_ERSPS_Favg_DFR_for_plot[[group]], aes(x=Y,y=X,fill=Z))+
    geom_tile()+
    ggtitle(paste0(group, " WMC in Favg during DFR"))+
    geom_vline(linetype = "dotted",xintercept = 11)+
    geom_vline(linetype = "dotted", xintercept = 61)+
    geom_vline(linetype= "dotted", xintercept = 122)+
    scale_y_continuous(labels = function(x){return(round(ERSPS_freqs[x+1], digits=2))},breaks = seq(0, 76, by = 5))+
    scale_x_continuous(labels = function(x){return(ERSPS_times_DFR[x+1])}, breaks = seq(0,150, by = 25))+
    scale_fill_gradient2(limits=c(-2.5, 1.75),breaks=seq.int(-2,1.5,1),low="blue",mid="white",high="red") +
    xlab("Time (ms)")+
    ylab("Frequency")+
    labs(fill="Power Load Effect")+
    theme_classic() 
}
split_ERSPS_midOccip_DFR_plots[["high"]] 

split_ERSPS_midOccip_DFR_plots[["med"]] 

split_ERSPS_midOccip_DFR_plots[["low"]]

split_ERSPS_Oz_DFR_plots[["high"]]

split_ERSPS_Oz_DFR_plots[["med"]]

split_ERSPS_Oz_DFR_plots[["low"]]

Inverted U shape relationships

Taking the linear correlation would obscure any inverted U shaped relationships - so let’s directly look for them by taking the values where abs(med) > abs(low) and abs(med) > abs(high) [taking absolute values to account for when the meaures are negative to baseline, which we see in EEG but don’t necessarily see in fMRI]

inverted_U_midOccip_ERSPS <- find_inverted_U_spectra(split_ERSPS_midOccip_DFR, apply(ERSPS_midOccip_DFR[["data"]][["load_effect"]],c(1,2),mean))
inverted_U_Oz_ERSPS <- find_inverted_U_spectra(split_ERSPS_Oz_DFR, apply(ERSPS_Oz_DFR[["data"]][["load_effect"]],c(1,2),mean))
inverted_U_Favg_ERSPS <- find_inverted_U_spectra(split_ERSPS_Favg_DFR, apply(ERSPS_Favg_DFR[["data"]][["load_effect"]],c(1,2),mean))

Here, we plot the spectra averaged over all subjects, but masked for where there is an inverted U shape relationship.

ggplot(data=inverted_U_midOccip_ERSPS, aes(x=Y,y=X,fill=Z))+
  geom_tile()+
  ggtitle("Inverted U relationship with WMC in midOccip cluster during DFR")+
  geom_vline(linetype = "dotted",xintercept = 11)+
  geom_vline(linetype = "dotted", xintercept = 61)+
  geom_vline(linetype= "dotted", xintercept = 122)+
  scale_y_continuous(labels = function(x){return(round(ERSPS_freqs[x+1], digits=2))},breaks = seq(0, 76, by = 5))+
  scale_x_continuous(labels = function(x){return(ERSPS_times_DFR[x+1])}, breaks = seq(0,150, by = 25))+
  scale_fill_gradient2(limits=c(-2.5, 1.75),breaks=seq.int(-2,1.5,1),low="blue",mid="white",high="red") +
  xlab("Time (ms)")+
  ylab("Frequency")+
  labs(fill="Power Load Effect")+
  theme_classic() 

ggplot(data=inverted_U_Oz_ERSPS, aes(x=Y,y=X,fill=Z))+
  geom_tile()+
  ggtitle("Inverted U relationship with WMC in Oz during DFR")+
  geom_vline(linetype = "dotted",xintercept = 11)+
  geom_vline(linetype = "dotted", xintercept = 61)+
  geom_vline(linetype= "dotted", xintercept = 122)+
  scale_y_continuous(labels = function(x){return(round(ERSPS_freqs[x+1], digits=2))},breaks = seq(0, 76, by = 5))+
  scale_x_continuous(labels = function(x){return(ERSPS_times_DFR[x+1])}, breaks = seq(0,150, by = 25))+
  scale_fill_gradient2(limits=c(-2.5, 1.75),breaks=seq.int(-2,1.5,1),low="blue",mid="white",high="red") +
  xlab("Time (ms)")+
  ylab("Frequency")+
  labs(fill="Power Load Effect")+
  theme_classic() 

Correlation to Omnibus Span

All correlations below are calculated robustly, such that outliers in EEG data > 3SD above or below the mean are removed.

Mid occipital cluster shows a positive correlation with span during the encoding and delay period in the beta and low gamma bands, and a negative correlation in the theta through alpha bands during the entire task, but most prominently right at the beginning of the probe period.

Oz shows a strong positive correlation with alpha power during encoding and what looks to be low gamma across the entire task. There also seems to be a negative correlation with beta across the entire task, with particularly strong negative correlations right at the end of the delay period/beginning of probe period.

ggplot(data=omnibus_span_corr[["ERSPS_midOccip_DFR"]][["plot"]],aes(x=Y,y=X,fill=Z))+
  geom_tile()+
  ggtitle("midOccip cluster during DFR")+
  geom_vline(linetype = "dotted",xintercept = 11)+
  geom_vline(linetype = "dotted", xintercept = 61)+
  geom_vline(linetype= "dotted", xintercept = 122)+
  scale_y_continuous(labels = function(x){return(round(ERSPS_freqs[x+1], digits=2))},breaks = seq(0, 76, by = 5))+
  scale_x_continuous(labels = function(x){return(ERSPS_times_DFR[x+1])}, breaks = seq(0,150, by = 25))+
  scale_fill_gradient2(low="blue",mid="white",
                       high="red") +
  xlab("Time (ms)")+
  ylab("Frequency")+
  labs(fill="Correlation")+
  theme_classic()

ggplot(data=omnibus_span_corr[["ERSPS_Oz_DFR"]][["plot"]],aes(x=Y,y=X,fill=Z))+
  geom_tile()+
  ggtitle("Oz electrode during DFR")+
  geom_vline(linetype = "dotted",xintercept = 11)+
  geom_vline(linetype = "dotted", xintercept = 61)+
  geom_vline(linetype= "dotted", xintercept = 122)+
  scale_y_continuous(labels = function(x){return(round(ERSPS_freqs[x+1], digits=2))},breaks = seq(0, 76, by = 5))+
  scale_x_continuous(labels = function(x){return(ERSPS_times_DFR[x+1])}, breaks = seq(0,150, by = 25))+
  scale_fill_gradient2(low="blue",mid="white",
                       high="red") +
  xlab("Time (ms)")+
  ylab("Frequency")+
  labs(fill="Correlation")+
  theme_classic()

ggplot(data=omnibus_span_corr[["ERSPS_midOccip_DFR"]][["thresholded_plot"]],aes(x=Y,y=X,fill=Z))+
  geom_tile()+
  ggtitle("midOccip cluster during DFR")+
  geom_vline(linetype = "dotted",xintercept = 11)+
  geom_vline(linetype = "dotted", xintercept = 61)+
  geom_vline(linetype= "dotted", xintercept = 122)+
  scale_y_continuous(labels = function(x){return(round(ERSPS_freqs[x+1], digits=2))},breaks = seq(0, 76, by = 5))+
  scale_x_continuous(labels = function(x){return(ERSPS_times_DFR[x+1])}, breaks = seq(0,150, by = 25))+
  scale_fill_gradient2(low="blue",mid="white",
                       high="red") +
  xlab("Time (ms)")+
  ylab("Frequency")+
  labs(fill="Correlation")+
  theme_classic()

ggplot(data=omnibus_span_corr[["ERSPS_Oz_DFR"]][["thresholded_plot"]],aes(x=Y,y=X,fill=Z))+
  geom_tile()+
  ggtitle("Oz electrode during DFR")+
  geom_vline(linetype = "dotted",xintercept = 11)+
  geom_vline(linetype = "dotted", xintercept = 61)+
  geom_vline(linetype= "dotted", xintercept = 122)+
  scale_y_continuous(labels = function(x){return(round(ERSPS_freqs[x+1], digits=2))},breaks = seq(0, 76, by = 5))+
  scale_x_continuous(labels = function(x){return(ERSPS_times_DFR[x+1])}, breaks = seq(0,150, by = 25))+
  scale_fill_gradient2(low="blue",mid="white",
                       high="red") +
  xlab("Time (ms)")+
  ylab("Frequency")+
  labs(fill="Correlation")+
  theme_classic()

Correlation to span squared

ggplot(data=omnibus_span_squared_corr[["ERSPS_midOccip_DFR"]][["plot"]],aes(x=Y,y=X,fill=Z))+
  geom_tile()+
  ggtitle("midOccip cluster during DFR")+
  geom_vline(linetype = "dotted",xintercept = 11)+
  geom_vline(linetype = "dotted", xintercept = 61)+
  geom_vline(linetype= "dotted", xintercept = 122)+
  scale_y_continuous(labels = function(x){return(round(ERSPS_freqs[x+1], digits=2))},breaks = seq(0, 76, by = 5))+
  scale_x_continuous(labels = function(x){return(ERSPS_times_DFR[x+1])}, breaks = seq(0,150, by = 25))+
  scale_fill_gradient2(low="blue",mid="white",
                       high="red") +
  xlab("Time (ms)")+
  ylab("Frequency")+
  labs(fill="Correlation")+
  theme_classic()

ggplot(data=omnibus_span_squared_corr[["ERSPS_Oz_DFR"]][["plot"]],aes(x=Y,y=X,fill=Z))+
  geom_tile()+
  ggtitle("Oz electrode during DFR")+
  geom_vline(linetype = "dotted",xintercept = 11)+
  geom_vline(linetype = "dotted", xintercept = 61)+
  geom_vline(linetype= "dotted", xintercept = 122)+
  scale_y_continuous(labels = function(x){return(round(ERSPS_freqs[x+1], digits=2))},breaks = seq(0, 76, by = 5))+
  scale_x_continuous(labels = function(x){return(ERSPS_times_DFR[x+1])}, breaks = seq(0,150, by = 25))+
  scale_fill_gradient2(low="blue",mid="white",
                       high="red") +
  xlab("Time (ms)")+
  ylab("Frequency")+
  labs(fill="Correlation")+
  theme_classic()

With span squared (a relative proxy for an inverted U shaped relationship), we do see a positive correlation of around 0.18 in the alpha band around the end of encoding survive FDR correction.

ggplot(data=omnibus_span_squared_corr[["ERSPS_midOccip_DFR"]][["thresholded_plot"]],aes(x=Y,y=X,fill=Z))+
  geom_tile()+
  ggtitle("midOccip cluster during DFR")+
  geom_vline(linetype = "dotted",xintercept = 11)+
  geom_vline(linetype = "dotted", xintercept = 61)+
  geom_vline(linetype= "dotted", xintercept = 122)+
  scale_y_continuous(labels = function(x){return(round(ERSPS_freqs[x+1], digits=2))},breaks = seq(0, 76, by = 5))+
  scale_x_continuous(labels = function(x){return(ERSPS_times_DFR[x+1])}, breaks = seq(0,150, by = 25))+
  scale_fill_gradient2(low="blue",mid="white",
                       high="red") +
  xlab("Time (ms)")+
  ylab("Frequency")+
  labs(fill="Correlation")+
  theme_classic()

ggplot(data=omnibus_span_squared_corr[["ERSPS_Oz_DFR"]][["thresholded_plot"]],aes(x=Y,y=X,fill=Z))+
  geom_tile()+
  ggtitle("Oz electrode during DFR")+
  geom_vline(linetype = "dotted",xintercept = 11)+
  geom_vline(linetype = "dotted", xintercept = 61)+
  geom_vline(linetype= "dotted", xintercept = 122)+
  scale_y_continuous(labels = function(x){return(round(ERSPS_freqs[x+1], digits=2))},breaks = seq(0, 76, by = 5))+
  scale_x_continuous(labels = function(x){return(ERSPS_times_DFR[x+1])}, breaks = seq(0,150, by = 25))+
  scale_fill_gradient2(low="blue",mid="white",
                       high="red") +
  xlab("Time (ms)")+
  ylab("Frequency")+
  labs(fill="Correlation")+
  theme_classic()

Correlation to DFR high load accuracy

ggplot(data=DFR_L3_acc_corr[["ERSPS_midOccip_DFR"]][["plot"]],aes(x=Y,y=X,fill=Z))+
  geom_tile()+
  ggtitle("midOccip cluster during DFR")+
  geom_vline(linetype = "dotted",xintercept = 11)+
  geom_vline(linetype = "dotted", xintercept = 61)+
  geom_vline(linetype= "dotted", xintercept = 122)+
  scale_y_continuous(labels = function(x){return(round(ERSPS_freqs[x+1], digits=2))},breaks = seq(0, 76, by = 5))+
  scale_x_continuous(labels = function(x){return(ERSPS_times_DFR[x+1])}, breaks = seq(0,150, by = 25))+
  scale_fill_gradient2(low="blue",mid="white",
                       high="red") +
  xlab("Time (ms)")+
  ylab("Frequency")+
  labs(fill="Correlation")+
  theme_classic()

ggplot(data=DFR_L3_acc_corr[["ERSPS_Oz_DFR"]][["plot"]],aes(x=Y,y=X,fill=Z))+
  geom_tile()+
  ggtitle("Oz electrode during DFR")+
  geom_vline(linetype = "dotted",xintercept = 11)+
  geom_vline(linetype = "dotted", xintercept = 61)+
  geom_vline(linetype= "dotted", xintercept = 122)+
  scale_y_continuous(labels = function(x){return(round(ERSPS_freqs[x+1], digits=2))},breaks = seq(0, 76, by = 5))+
  scale_x_continuous(labels = function(x){return(ERSPS_times_DFR[x+1])}, breaks = seq(0,150, by = 25))+
  scale_fill_gradient2(low="blue",mid="white",
                       high="red") +
  xlab("Time (ms)")+
  ylab("Frequency")+
  labs(fill="Correlation")+
  theme_classic()

ggplot(data=DFR_L3_acc_corr[["ERSPS_midOccip_DFR"]][["thresholded_plot"]],aes(x=Y,y=X,fill=Z))+
  geom_tile()+
  ggtitle("midOccip cluster during DFR")+
  geom_vline(linetype = "dotted",xintercept = 11)+
  geom_vline(linetype = "dotted", xintercept = 61)+
  geom_vline(linetype= "dotted", xintercept = 122)+
  scale_y_continuous(labels = function(x){return(round(ERSPS_freqs[x+1], digits=2))},breaks = seq(0, 76, by = 5))+
  scale_x_continuous(labels = function(x){return(ERSPS_times_DFR[x+1])}, breaks = seq(0,150, by = 25))+
  scale_fill_gradient2(low="blue",mid="white",
                       high="red") +
  xlab("Time (ms)")+
  ylab("Frequency")+
  labs(fill="Correlation")+
  theme_classic()

ggplot(data=DFR_L3_acc_corr[["ERSPS_Oz_DFR"]][["thresholded_plot"]],aes(x=Y,y=X,fill=Z))+
  geom_tile()+
  ggtitle("Oz electrode during DFR")+
  geom_vline(linetype = "dotted",xintercept = 11)+
  geom_vline(linetype = "dotted", xintercept = 61)+
  geom_vline(linetype= "dotted", xintercept = 122)+
  scale_y_continuous(labels = function(x){return(round(ERSPS_freqs[x+1], digits=2))},breaks = seq(0, 76, by = 5))+
  scale_x_continuous(labels = function(x){return(ERSPS_times_DFR[x+1])}, breaks = seq(0,150, by = 25))+
  scale_fill_gradient2(low="blue",mid="white",
                       high="red") +
  xlab("Time (ms)")+
  ylab("Frequency")+
  labs(fill="Correlation")+
  theme_classic()

Correlation to DFR fMRI load effect

There seems to be a strong correlation between fMRI load effect and power in the alpha and beta band across electrodes, particularly during encoding, though it doesn’t survive FDR correction.

ggplot(data=DFR_fMRI_LE_corr[["ERSPS_midOccip_DFR"]][["plot"]],aes(x=Y,y=X,fill=Z))+
  geom_tile()+
  ggtitle("midOccip cluster during DFR")+
  geom_vline(linetype = "dotted",xintercept = 11)+
  geom_vline(linetype = "dotted", xintercept = 61)+
  geom_vline(linetype= "dotted", xintercept = 122)+
  scale_y_continuous(labels = function(x){return(round(ERSPS_freqs[x+1], digits=2))},breaks = seq(0, 76, by = 5))+
  scale_x_continuous(labels = function(x){return(ERSPS_times_DFR[x+1])}, breaks = seq(0,150, by = 25))+
  scale_fill_gradient2(low="blue",mid="white",
                       high="red") +
  xlab("Time (ms)")+
  ylab("Frequency")+
  labs(fill="Correlation")+
  theme_classic()

ggplot(data=DFR_fMRI_LE_corr[["ERSPS_Oz_DFR"]][["plot"]],aes(x=Y,y=X,fill=Z))+
  geom_tile()+
  ggtitle("Oz electrode during DFR")+
  geom_vline(linetype = "dotted",xintercept = 11)+
  geom_vline(linetype = "dotted", xintercept = 61)+
  geom_vline(linetype= "dotted", xintercept = 122)+
  scale_y_continuous(labels = function(x){return(round(ERSPS_freqs[x+1], digits=2))},breaks = seq(0, 76, by = 5))+
  scale_x_continuous(labels = function(x){return(ERSPS_times_DFR[x+1])}, breaks = seq(0,150, by = 25))+
  scale_fill_gradient2(low="blue",mid="white",
                       high="red") +
  xlab("Time (ms)")+
  ylab("Frequency")+
  labs(fill="Correlation")+
  theme_classic()

ggplot(data=DFR_fMRI_LE_corr[["ERSPS_midOccip_DFR"]][["thresholded_plot"]],aes(x=Y,y=X,fill=Z))+
  geom_tile()+
  ggtitle("midOccip cluster during DFR")+
  geom_vline(linetype = "dotted",xintercept = 11)+
  geom_vline(linetype = "dotted", xintercept = 61)+
  geom_vline(linetype= "dotted", xintercept = 122)+
  scale_y_continuous(labels = function(x){return(round(ERSPS_freqs[x+1], digits=2))},breaks = seq(0, 76, by = 5))+
  scale_x_continuous(labels = function(x){return(ERSPS_times_DFR[x+1])}, breaks = seq(0,150, by = 25))+
  scale_fill_gradient2(low="blue",mid="white",
                       high="red") +
  xlab("Time (ms)")+
  ylab("Frequency")+
  labs(fill="Correlation")+
  theme_classic()

ggplot(data=DFR_fMRI_LE_corr[["ERSPS_Oz_DFR"]][["thresholded_plot"]],aes(x=Y,y=X,fill=Z))+
  geom_tile()+
  ggtitle("Oz electrode during DFR")+
  geom_vline(linetype = "dotted",xintercept = 11)+
  geom_vline(linetype = "dotted", xintercept = 61)+
  geom_vline(linetype= "dotted", xintercept = 122)+
  scale_y_continuous(labels = function(x){return(round(ERSPS_freqs[x+1], digits=2))},breaks = seq(0, 76, by = 5))+
  scale_x_continuous(labels = function(x){return(ERSPS_times_DFR[x+1])}, breaks = seq(0,150, by = 25))+
  scale_fill_gradient2(low="blue",mid="white",
                       high="red") +
  xlab("Time (ms)")+
  ylab("Frequency")+
  labs(fill="Correlation")+
  theme_classic()

alpha <- list(
  
  ERSPS_midOccip_DFR = list(
    high_load = data.frame(PTID = ERSPS_midOccip_DFR$PTID,t(apply(ERSPS_midOccip_DFR[["data"]][["high_load"]][26:38,,], c(2,3), mean))),
    low_load = data.frame(PTID = ERSPS_midOccip_DFR$PTID,t(apply(ERSPS_midOccip_DFR[["data"]][["low_load"]][26:38,,], c(2,3), mean))),
    load_effect = data.frame(PTID = ERSPS_midOccip_DFR$PTID,t(apply(ERSPS_midOccip_DFR[["data"]][["load_effect"]][26:38,,], c(2,3), mean)))),  
  
  ERSPS_Favg_DFR = list(
    high_load = data.frame(PTID = ERSPS_Favg_DFR$PTID,t(apply(ERSPS_Favg_DFR[["data"]][["high_load"]][26:38,,], c(2,3), mean))),
    low_load = data.frame(PTID = ERSPS_Favg_DFR$PTID,t(apply(ERSPS_Favg_DFR[["data"]][["low_load"]][26:38,,], c(2,3), mean))),
    load_effect = data.frame(PTID = ERSPS_Favg_DFR$PTID,t(apply(ERSPS_Favg_DFR[["data"]][["load_effect"]][26:38,,], c(2,3), mean)))),  
  
  ERSPS_Oz_DFR = list(
    high_load = data.frame(PTID = ERSPS_Oz_DFR$PTID,t(apply(ERSPS_Oz_DFR[["data"]][["high_load"]][26:38,,], c(2,3), mean))),
    low_load = data.frame(PTID = ERSPS_Oz_DFR$PTID,t(apply(ERSPS_Oz_DFR[["data"]][["low_load"]][26:38,,], c(2,3), mean))),
    load_effect = data.frame(PTID = ERSPS_Oz_DFR$PTID,t(apply(ERSPS_Oz_DFR[["data"]][["load_effect"]][26:38,,], c(2,3), mean))))
)

low_alpha <- list(
  
  ERSPS_midOccip_DFR = list(
    high_load = data.frame(PTID = ERSPS_midOccip_DFR$PTID,t(apply(ERSPS_midOccip_DFR[["data"]][["high_load"]][26:32,,], c(2,3), mean))),
    low_load = data.frame(PTID = ERSPS_midOccip_DFR$PTID,t(apply(ERSPS_midOccip_DFR[["data"]][["low_load"]][26:32,,], c(2,3), mean))),
    load_effect = data.frame(PTID = ERSPS_midOccip_DFR$PTID,t(apply(ERSPS_midOccip_DFR[["data"]][["load_effect"]][26:32,,], c(2,3), mean)))),  
  
  ERSPS_Favg_DFR = list(
    high_load = data.frame(PTID = ERSPS_Favg_DFR$PTID,t(apply(ERSPS_Favg_DFR[["data"]][["high_load"]][26:32,,], c(2,3), mean))),
    low_load = data.frame(PTID = ERSPS_Favg_DFR$PTID,t(apply(ERSPS_Favg_DFR[["data"]][["low_load"]][26:32,,], c(2,3), mean))),
    load_effect = data.frame(PTID = ERSPS_Favg_DFR$PTID,t(apply(ERSPS_Favg_DFR[["data"]][["load_effect"]][26:32,,], c(2,3), mean)))),  
  
  ERSPS_Oz_DFR = list(
    high_load = data.frame(PTID = ERSPS_Oz_DFR$PTID,t(apply(ERSPS_Oz_DFR[["data"]][["high_load"]][26:32,,], c(2,3), mean))),
    low_load = data.frame(PTID = ERSPS_Oz_DFR$PTID,t(apply(ERSPS_Oz_DFR[["data"]][["low_load"]][26:32,,], c(2,3), mean))),
    load_effect = data.frame(PTID = ERSPS_Oz_DFR$PTID,t(apply(ERSPS_Oz_DFR[["data"]][["load_effect"]][26:32,,], c(2,3), mean))))
)

high_alpha <- list(
  
  ERSPS_midOccip_DFR = list(
    high_load = data.frame(PTID = ERSPS_midOccip_DFR$PTID,t(apply(ERSPS_midOccip_DFR[["data"]][["high_load"]][32:38,,], c(2,3), mean))),
    low_load = data.frame(PTID = ERSPS_midOccip_DFR$PTID,t(apply(ERSPS_midOccip_DFR[["data"]][["low_load"]][32:38,,], c(2,3), mean))),
    load_effect = data.frame(PTID = ERSPS_midOccip_DFR$PTID,t(apply(ERSPS_midOccip_DFR[["data"]][["load_effect"]][32:38,,], c(2,3), mean)))),  
  
  ERSPS_Favg_DFR = list(
    high_load = data.frame(PTID = ERSPS_Favg_DFR$PTID,t(apply(ERSPS_Favg_DFR[["data"]][["high_load"]][32:38,,], c(2,3), mean))),
    low_load = data.frame(PTID = ERSPS_Favg_DFR$PTID,t(apply(ERSPS_Favg_DFR[["data"]][["low_load"]][32:38,,], c(2,3), mean))),
    load_effect = data.frame(PTID = ERSPS_Favg_DFR$PTID,t(apply(ERSPS_Favg_DFR[["data"]][["load_effect"]][32:38,,], c(2,3), mean)))),  
  
  ERSPS_Oz_DFR = list(
    high_load = data.frame(PTID = ERSPS_Oz_DFR$PTID,t(apply(ERSPS_Oz_DFR[["data"]][["high_load"]][32:38,,], c(2,3), mean))),
    low_load = data.frame(PTID = ERSPS_Oz_DFR$PTID,t(apply(ERSPS_Oz_DFR[["data"]][["low_load"]][32:38,,], c(2,3), mean))),
    load_effect = data.frame(PTID = ERSPS_Oz_DFR$PTID,t(apply(ERSPS_Oz_DFR[["data"]][["load_effect"]][32:38,,], c(2,3), mean))))
)

beta <- list(
  
  ERSPS_midOccip_DFR = list(
    high_load = data.frame(PTID = ERSPS_midOccip_DFR$PTID,t(apply(ERSPS_midOccip_DFR[["data"]][["high_load"]][37:45,,], c(2,3), mean))),
    low_load = data.frame(PTID = ERSPS_midOccip_DFR$PTID,t(apply(ERSPS_midOccip_DFR[["data"]][["low_load"]][37:45,,], c(2,3), mean))),
    load_effect = data.frame(PTID = ERSPS_midOccip_DFR$PTID,t(apply(ERSPS_midOccip_DFR[["data"]][["load_effect"]][37:45,,], c(2,3), mean)))),  
  
  ERSPS_Favg_DFR = list(
    high_load = data.frame(PTID = ERSPS_Favg_DFR$PTID,t(apply(ERSPS_Favg_DFR[["data"]][["high_load"]][37:45,,], c(2,3), mean))),
    low_load = data.frame(PTID = ERSPS_Favg_DFR$PTID,t(apply(ERSPS_Favg_DFR[["data"]][["low_load"]][37:45,,], c(2,3), mean))),
    load_effect = data.frame(PTID = ERSPS_Favg_DFR$PTID,t(apply(ERSPS_Favg_DFR[["data"]][["load_effect"]][37:45,,], c(2,3), mean)))),
  
  ERSPS_Oz_DFR = list(
    high_load = data.frame(PTID = ERSPS_Oz_DFR$PTID,t(apply(ERSPS_Oz_DFR[["data"]][["high_load"]][37:45,,], c(2,3), mean))),
    low_load = data.frame(PTID = ERSPS_Oz_DFR$PTID,t(apply(ERSPS_Oz_DFR[["data"]][["low_load"]][37:45,,], c(2,3), mean))),
    load_effect = data.frame(PTID = ERSPS_Oz_DFR$PTID,t(apply(ERSPS_Oz_DFR[["data"]][["load_effect"]][37:45,,], c(2,3), mean))))
)

theta <- list(
  
  ERSPS_midOccip_DFR = list(
    high_load = data.frame(PTID = ERSPS_midOccip_DFR$PTID,t(apply(ERSPS_midOccip_DFR[["data"]][["high_load"]][1:25,,], c(2,3), mean))),
    low_load = data.frame(PTID = ERSPS_midOccip_DFR$PTID,t(apply(ERSPS_midOccip_DFR[["data"]][["low_load"]][1:25,,], c(2,3), mean))),
    load_effect = data.frame(PTID = ERSPS_midOccip_DFR$PTID,t(apply(ERSPS_midOccip_DFR[["data"]][["load_effect"]][1:25,,], c(2,3), mean)))),  
  
  ERSPS_Favg_DFR = list(
    high_load = data.frame(PTID = ERSPS_Favg_DFR$PTID,t(apply(ERSPS_Favg_DFR[["data"]][["high_load"]][1:25,,], c(2,3), mean))),
    low_load = data.frame(PTID = ERSPS_Favg_DFR$PTID,t(apply(ERSPS_Favg_DFR[["data"]][["low_load"]][1:25,,], c(2,3), mean))),
    load_effect = data.frame(PTID = ERSPS_Favg_DFR$PTID,t(apply(ERSPS_Favg_DFR[["data"]][["load_effect"]][1:25,,], c(2,3), mean)))),
  
  ERSPS_Oz_DFR = list(
    high_load = data.frame(PTID = ERSPS_Oz_DFR$PTID,t(apply(ERSPS_Oz_DFR[["data"]][["high_load"]][1:25,,], c(2,3), mean))),
    low_load = data.frame(PTID = ERSPS_Oz_DFR$PTID,t(apply(ERSPS_Oz_DFR[["data"]][["low_load"]][1:25,,], c(2,3), mean))),
    load_effect = data.frame(PTID = ERSPS_Oz_DFR$PTID,t(apply(ERSPS_Oz_DFR[["data"]][["load_effect"]][1:25,,], c(2,3), mean))))
)

low_gamma <- list(
  
  ERSPS_midOccip_DFR = list(
    high_load = data.frame(PTID = ERSPS_midOccip_DFR$PTID,t(apply(ERSPS_midOccip_DFR[["data"]][["high_load"]][61:75,,], c(2,3), mean))),
    low_load = data.frame(PTID = ERSPS_midOccip_DFR$PTID,t(apply(ERSPS_midOccip_DFR[["data"]][["low_load"]][61:75,,], c(2,3), mean))),
    load_effect = data.frame(PTID = ERSPS_midOccip_DFR$PTID,t(apply(ERSPS_midOccip_DFR[["data"]][["load_effect"]][61:75,,], c(2,3), mean)))),  
  
  ERSPS_Favg_DFR = list(
    high_load = data.frame(PTID = ERSPS_Favg_DFR$PTID,t(apply(ERSPS_Favg_DFR[["data"]][["high_load"]][61:75,,], c(2,3), mean))),
    low_load = data.frame(PTID = ERSPS_Favg_DFR$PTID,t(apply(ERSPS_Favg_DFR[["data"]][["low_load"]][61:75,,], c(2,3), mean))),
    load_effect = data.frame(PTID = ERSPS_Favg_DFR$PTID,t(apply(ERSPS_Favg_DFR[["data"]][["load_effect"]][61:75,,], c(2,3), mean)))),
  
  ERSPS_Oz_DFR = list(
    high_load = data.frame(PTID = ERSPS_Oz_DFR$PTID,t(apply(ERSPS_Oz_DFR[["data"]][["high_load"]][61:75,,], c(2,3), mean))),
    low_load = data.frame(PTID = ERSPS_Oz_DFR$PTID,t(apply(ERSPS_Oz_DFR[["data"]][["low_load"]][61:75,,], c(2,3), mean))),
    load_effect = data.frame(PTID = ERSPS_Oz_DFR$PTID,t(apply(ERSPS_Oz_DFR[["data"]][["load_effect"]][61:75,,], c(2,3), mean))))
)
alpha_list <- list(
  ERSPS_midOccip_DFR = data.frame(
    high_load = apply(alpha[["ERSPS_midOccip_DFR"]][["high_load"]][,2:153], 2, mean),
    low_load = apply(alpha[["ERSPS_midOccip_DFR"]][["low_load"]][,2:153], 2, mean),
    load_effect = apply(alpha[["ERSPS_midOccip_DFR"]][["load_effect"]][,2:153], 2, mean),
    time = ERSPS_times_DFR),  
  ERSPS_Oz_DFR = data.frame(
    high_load = apply(alpha[["ERSPS_Oz_DFR"]][["high_load"]][,2:153], 2, mean),
    low_load = apply(alpha[["ERSPS_Oz_DFR"]][["low_load"]][,2:153], 2, mean),
    load_effect = apply(alpha[["ERSPS_Oz_DFR"]][["load_effect"]][,2:153], 2, mean),
    time = ERSPS_times_DFR),
  ERSPS_Favg_DFR = data.frame(
    high_load = apply(alpha[["ERSPS_Favg_DFR"]][["high_load"]][,2:153], 2, mean),
    low_load = apply(alpha[["ERSPS_Favg_DFR"]][["low_load"]][,2:153], 2, mean),
    load_effect = apply(alpha[["ERSPS_Favg_DFR"]][["load_effect"]][,2:153], 2, mean),
    time = ERSPS_times_DFR)
)


low_alpha_list <- list(
  ERSPS_midOccip_DFR = data.frame(
    high_load = apply(low_alpha[["ERSPS_midOccip_DFR"]][["high_load"]][,2:153], 2, mean),
    low_load = apply(low_alpha[["ERSPS_midOccip_DFR"]][["low_load"]][,2:153], 2, mean),
    load_effect = apply(low_alpha[["ERSPS_midOccip_DFR"]][["load_effect"]][,2:153], 2, mean),
    time = ERSPS_times_DFR),  
  ERSPS_Oz_DFR = data.frame(
    high_load = apply(low_alpha[["ERSPS_Oz_DFR"]][["high_load"]][,2:153], 2, mean),
    low_load = apply(low_alpha[["ERSPS_Oz_DFR"]][["low_load"]][,2:153], 2, mean),
    load_effect = apply(low_alpha[["ERSPS_Oz_DFR"]][["load_effect"]][,2:153], 2, mean),
    time = ERSPS_times_DFR),
  ERSPS_Favg_DFR = data.frame(
    high_load = apply(low_alpha[["ERSPS_Favg_DFR"]][["high_load"]][,2:153], 2, mean),
    low_load = apply(low_alpha[["ERSPS_Favg_DFR"]][["low_load"]][,2:153], 2, mean),
    load_effect = apply(low_alpha[["ERSPS_Favg_DFR"]][["load_effect"]][,2:153], 2, mean),
    time = ERSPS_times_DFR)
)

high_alpha_list <- list(
  ERSPS_midOccip_DFR = data.frame(
    high_load = apply(high_alpha[["ERSPS_midOccip_DFR"]][["high_load"]][,2:153], 2, mean),
    low_load = apply(high_alpha[["ERSPS_midOccip_DFR"]][["low_load"]][,2:153], 2, mean),
    load_effect = apply(high_alpha[["ERSPS_midOccip_DFR"]][["load_effect"]][,2:153], 2, mean),
    time = ERSPS_times_DFR),  
  ERSPS_Oz_DFR = data.frame(
    high_load = apply(high_alpha[["ERSPS_Oz_DFR"]][["high_load"]][,2:153], 2, mean),
    low_load = apply(high_alpha[["ERSPS_Oz_DFR"]][["low_load"]][,2:153], 2, mean),
    load_effect = apply(high_alpha[["ERSPS_Oz_DFR"]][["load_effect"]][,2:153], 2, mean),
    time = ERSPS_times_DFR),
  ERSPS_Favg_DFR = data.frame(
    high_load = apply(high_alpha[["ERSPS_Favg_DFR"]][["high_load"]][,2:153], 2, mean),
    low_load = apply(high_alpha[["ERSPS_Favg_DFR"]][["low_load"]][,2:153], 2, mean),
    load_effect = apply(high_alpha[["ERSPS_Favg_DFR"]][["load_effect"]][,2:153], 2, mean),
    time = ERSPS_times_DFR)
)

beta_list <- list(
  ERSPS_midOccip_DFR = data.frame(
    high_load = apply(beta[["ERSPS_midOccip_DFR"]][["high_load"]][,2:153], 2, mean),
    low_load = apply(beta[["ERSPS_midOccip_DFR"]][["low_load"]][,2:153], 2, mean),
    load_effect = apply(beta[["ERSPS_midOccip_DFR"]][["load_effect"]][,2:153], 2, mean),
    time = ERSPS_times_DFR),  
  ERSPS_Oz_DFR = data.frame(
    high_load = apply(beta[["ERSPS_Oz_DFR"]][["high_load"]][,2:153], 2, mean),
    low_load = apply(beta[["ERSPS_Oz_DFR"]][["low_load"]][,2:153], 2, mean),
    load_effect = apply(beta[["ERSPS_Oz_DFR"]][["load_effect"]][,2:153], 2, mean),
    time = ERSPS_times_DFR),
  ERSPS_Favg_DFR = data.frame(
    high_load = apply(beta[["ERSPS_Favg_DFR"]][["high_load"]][,2:153], 2, mean),
    low_load = apply(beta[["ERSPS_Favg_DFR"]][["low_load"]][,2:153], 2, mean),
    load_effect = apply(beta[["ERSPS_Favg_DFR"]][["load_effect"]][,2:153], 2, mean),
    time = ERSPS_times_DFR)
)

theta_list <- list(
  ERSPS_midOccip_DFR = data.frame(
    high_load = apply(theta[["ERSPS_midOccip_DFR"]][["high_load"]][,2:153], 2, mean),
    low_load = apply(theta[["ERSPS_midOccip_DFR"]][["low_load"]][,2:153], 2, mean),
    load_effect = apply(theta[["ERSPS_midOccip_DFR"]][["load_effect"]][,2:153], 2, mean),
    time = ERSPS_times_DFR),  
  ERSPS_Oz_DFR = data.frame(
    high_load = apply(theta[["ERSPS_Oz_DFR"]][["high_load"]][,2:153], 2, mean),
    low_load = apply(theta[["ERSPS_Oz_DFR"]][["low_load"]][,2:153], 2, mean),
    load_effect = apply(theta[["ERSPS_Oz_DFR"]][["load_effect"]][,2:153], 2, mean),
    time = ERSPS_times_DFR),
  ERSPS_Favg_DFR = data.frame(
    high_load = apply(theta[["ERSPS_Favg_DFR"]][["high_load"]][,2:153], 2, mean),
    low_load = apply(theta[["ERSPS_Favg_DFR"]][["low_load"]][,2:153], 2, mean),
    load_effect = apply(theta[["ERSPS_Favg_DFR"]][["load_effect"]][,2:153], 2, mean),
    time = ERSPS_times_DFR)
)

low_gamma_list <- list(
  ERSPS_midOccip_DFR = data.frame(
    high_load = apply(low_gamma[["ERSPS_midOccip_DFR"]][["high_load"]][,2:153], 2, mean),
    low_load = apply(low_gamma[["ERSPS_midOccip_DFR"]][["low_load"]][,2:153], 2, mean),
    load_effect = apply(low_gamma[["ERSPS_midOccip_DFR"]][["load_effect"]][,2:153], 2, mean),
    time = ERSPS_times_DFR),  
  ERSPS_Oz_DFR = data.frame(
    high_load = apply(low_gamma[["ERSPS_Oz_DFR"]][["high_load"]][,2:153], 2, mean),
    low_load = apply(low_gamma[["ERSPS_Oz_DFR"]][["low_load"]][,2:153], 2, mean),
    load_effect = apply(low_gamma[["ERSPS_Oz_DFR"]][["load_effect"]][,2:153], 2, mean),
    time = ERSPS_times_DFR),
  ERSPS_Favg_DFR = data.frame(
    high_load = apply(low_gamma[["ERSPS_Favg_DFR"]][["high_load"]][,2:153], 2, mean),
    low_load = apply(low_gamma[["ERSPS_Favg_DFR"]][["low_load"]][,2:153], 2, mean),
    load_effect = apply(low_gamma[["ERSPS_Favg_DFR"]][["load_effect"]][,2:153], 2, mean),
    time = ERSPS_times_DFR)
)
alpha_plot_list <- list()
low_alpha_plot_list <- list()
high_alpha_plot_list <- list()
beta_plot_list <- list()
theta_plot_list <- list()
low_gamma_plot_list <- list()

for (cluster in seq.int(1,length(alpha))){
  alpha_plot_list[[names(alpha_list)[cluster]]][["indiv_loads"]] <- ggplot(data = alpha_list[[cluster]])+
    geom_rect(data=rects,aes(xmin=xstart, xmax=xend, ymin = -Inf, ymax=Inf,alpha =0.005),fill="grey",show.legend = FALSE)+
    geom_line(aes(x=time,y=high_load))+
    geom_line(aes(x=time,y=low_load),linetype="dotted")+
    ylab("alpha power")+
    ggtitle("Low Load vs High Load")+
    scale_x_continuous(breaks = seq(-500,7000, by = 1000))+
    theme_classic()
  
  low_alpha_plot_list[[names(low_alpha_list)[cluster]]][["indiv_loads"]] <- ggplot(data = low_alpha_list[[cluster]])+
    geom_rect(data=rects,aes(xmin=xstart, xmax=xend, ymin = -Inf, ymax=Inf,alpha =0.005),fill="grey",show.legend = FALSE)+
    geom_line(aes(x=time,y=high_load))+
    geom_line(aes(x=time,y=low_load),linetype="dotted")+
    ylab("Low Alpha power")+
    ggtitle("Low Load vs High Load")+
    scale_x_continuous(breaks = seq(-500,7000, by = 1000))+
    theme_classic()
  
  high_alpha_plot_list[[names(high_alpha_list)[cluster]]][["indiv_loads"]] <- ggplot(data = high_alpha_list[[cluster]])+
    geom_rect(data=rects,aes(xmin=xstart, xmax=xend, ymin = -Inf, ymax=Inf,alpha =0.005),fill="grey",show.legend = FALSE)+
    geom_line(aes(x=time,y=high_load))+
    geom_line(aes(x=time,y=high_load),linetype="dotted")+
    ylab("High Alpha power")+
    ggtitle("Low Load vs High Load")+
    scale_x_continuous(breaks = seq(-500,7000, by = 1000))+
    theme_classic()
  
  alpha_plot_list[[names(alpha_list)[cluster]]][["LE"]] <- ggplot(data = alpha_list[[cluster]])+
    geom_rect(data=rects,aes(xmin=xstart, xmax=xend, ymin = -Inf, ymax=Inf,alpha =0.005),fill="grey",show.legend = FALSE)+
    geom_line(aes(x=time,y=load_effect))+
    ylab("alpha power")+
    ggtitle("Load Effect")+
    scale_x_continuous(breaks = seq(-500,7000, by = 1000))+
    theme_classic()
  
  low_alpha_plot_list[[names(low_alpha_list)[cluster]]][["LE"]] <- ggplot(data = low_alpha_list[[cluster]])+
    geom_rect(data=rects,aes(xmin=xstart, xmax=xend, ymin = -Inf, ymax=Inf,alpha =0.005),fill="grey",show.legend = FALSE)+
    geom_line(aes(x=time,y=load_effect))+
    ylab("low_alpha power")+
    ggtitle("Load Effect")+
    scale_x_continuous(breaks = seq(-500,7000, by = 1000))+
    theme_classic()
  
  high_alpha_plot_list[[names(high_alpha_list)[cluster]]][["LE"]] <- ggplot(data = high_alpha_list[[cluster]])+
    geom_rect(data=rects,aes(xmin=xstart, xmax=xend, ymin = -Inf, ymax=Inf,alpha =0.005),fill="grey",show.legend = FALSE)+
    geom_line(aes(x=time,y=load_effect))+
    ylab("high_alpha power")+
    ggtitle("Load Effect")+
    scale_x_continuous(breaks = seq(-500,7000, by = 1000))+
    theme_classic()  
}

for (cluster in seq.int(1,length(beta))){
  beta_plot_list[[names(beta_list)[cluster]]][["indiv_loads"]] <- ggplot(data = beta_list[[cluster]])+
    geom_rect(data=rects,aes(xmin=xstart, xmax=xend, ymin = -Inf, ymax=Inf,alpha =0.005),fill="grey",show.legend = FALSE)+
    geom_line(aes(x=time,y=high_load))+
    geom_line(aes(x=time,y=low_load),linetype="dotted")+
    ylab("beta power")+
    ggtitle("Low Load vs High Load")+
    scale_x_continuous(breaks = seq(-500,7000, by = 1000))+
    theme_classic()
  
  beta_plot_list[[names(beta_list)[cluster]]][["LE"]] <- ggplot(data = beta_list[[cluster]])+
    geom_rect(data=rects,aes(xmin=xstart, xmax=xend, ymin = -Inf, ymax=Inf,alpha =0.005),fill="grey",show.legend = FALSE)+
    geom_line(aes(x=time,y=load_effect))+
    ylab("beta power")+
    ggtitle("Load Effect")+
    scale_x_continuous(breaks = seq(-500,7000, by = 1000))+
    theme_classic()
  
}

for (cluster in seq.int(1,length(theta))){
  theta_plot_list[[names(theta_list)[cluster]]][["indiv_loads"]] <- ggplot(data = theta_list[[cluster]])+
    geom_rect(data=rects,aes(xmin=xstart, xmax=xend, ymin = -Inf, ymax=Inf,alpha =0.005),fill="grey",show.legend = FALSE)+
    geom_line(aes(x=time,y=high_load))+
    geom_line(aes(x=time,y=low_load),linetype="dotted")+
    ylab("theta power")+
    ggtitle("Low Load vs High Load")+
    scale_x_continuous(breaks = seq(-500,7000, by = 1000))+
    theme_classic()
  
  theta_plot_list[[names(theta_list)[cluster]]][["LE"]] <- ggplot(data = theta_list[[cluster]])+
    geom_rect(data=rects,aes(xmin=xstart, xmax=xend, ymin = -Inf, ymax=Inf,alpha =0.005),fill="grey",show.legend = FALSE)+
    geom_line(aes(x=time,y=load_effect))+
    ylab("theta power")+
    ggtitle("Load Effect")+
    scale_x_continuous(breaks = seq(-500,7000, by = 1000))+
    theme_classic()
  
}

for (cluster in seq.int(1,length(low_gamma))){
  low_gamma_plot_list[[names(low_gamma_list)[cluster]]][["indiv_loads"]] <- ggplot(data = low_gamma_list[[cluster]])+
    geom_rect(data=rects,aes(xmin=xstart, xmax=xend, ymin = -Inf, ymax=Inf,alpha =0.005),fill="grey",show.legend = FALSE)+
    geom_line(aes(x=time,y=high_load))+
    geom_line(aes(x=time,y=low_load),linetype="dotted")+
    ylab("low_gamma power")+
    ggtitle("Low Load vs High Load")+
    scale_x_continuous(breaks = seq(-500,7000, by = 1000))+
    theme_classic()
  
  low_gamma_plot_list[[names(low_gamma_list)[cluster]]][["LE"]] <- ggplot(data = low_gamma_list[[cluster]])+
    geom_rect(data=rects,aes(xmin=xstart, xmax=xend, ymin = -Inf, ymax=Inf,alpha =0.005),fill="grey",show.legend = FALSE)+
    geom_line(aes(x=time,y=load_effect))+
    ylab("low_gamma power")+
    ggtitle("Load Effect")+
    scale_x_continuous(breaks = seq(-500,7000, by = 1000))+
    theme_classic()
  
}

Alpha

All Subjects

When we look at the load effects over all subjects, we see significant load effects in the alpha band during the cue and probe period in Oz, mid Occipital cluster and F average electrodes and during the delay period in the Oz electrode. During the cue and probe periods, we see stronger power in the low load, but we see the opposite effect in the delay period.

alpha_plot_list[["ERSPS_midOccip_DFR"]][["indiv_loads"]] + alpha_plot_list[["ERSPS_midOccip_DFR"]][["LE"]] +
  plot_annotation(title="midOccip - alpha during DFR")

alpha_plot_list[["ERSPS_Oz_DFR"]][["indiv_loads"]] + alpha_plot_list[["ERSPS_Oz_DFR"]][["LE"]] +
  plot_annotation(title="Oz - alpha during DFR")

We only want to average over time points with signficant load effects, so pull those out. For the delay period, we’re only looking at early delay period.

alpha_mid_occip_times <- time_sig_load_effects(alpha[["ERSPS_midOccip_DFR"]][["load_effect"]], ERSPS_times_DFR)
alpha_Oz_times <- time_sig_load_effects(alpha[["ERSPS_Oz_DFR"]][["load_effect"]], ERSPS_times_DFR)

high_alpha_mid_occip_times <- time_sig_load_effects(high_alpha[["ERSPS_midOccip_DFR"]][["load_effect"]], ERSPS_times_DFR)
high_alpha_Oz_times <- time_sig_load_effects(high_alpha[["ERSPS_Oz_DFR"]][["load_effect"]], ERSPS_times_DFR)

low_alpha_mid_occip_times <- time_sig_load_effects(low_alpha[["ERSPS_midOccip_DFR"]][["load_effect"]], ERSPS_times_DFR)
low_alpha_Oz_times <- time_sig_load_effects(low_alpha[["ERSPS_Oz_DFR"]][["load_effect"]], ERSPS_times_DFR)
alpha_cue_average_midOccip <- select_period_average(alpha[["ERSPS_midOccip_DFR"]],843.75000,2531.25,ERSPS_times_DFR)
alpha_cue_average_Oz <- select_period_average(alpha[["ERSPS_Oz_DFR"]],1140.62500,2531.25,ERSPS_times_DFR)

alpha_delay_average_midOccip <- select_period_average(alpha[["ERSPS_midOccip_DFR"]],2531.25,3175.78125,ERSPS_times_DFR)
alpha_delay_average_Oz <- select_period_average(alpha[["ERSPS_Oz_DFR"]],2531.25,3078.12500,ERSPS_times_DFR)

alpha_probe_average_midOccip <- select_period_average(alpha[["ERSPS_midOccip_DFR"]],6007.81250,6800.78125,ERSPS_times_DFR)
alpha_probe_average_Oz <- select_period_average(alpha[["ERSPS_Oz_DFR"]],6007.81250,6902.34375,ERSPS_times_DFR)
low_alpha_cue_average_midOccip <- select_period_average(low_alpha[["ERSPS_midOccip_DFR"]],890.62500,2531.25,ERSPS_times_DFR)
low_alpha_cue_average_Oz <- select_period_average(low_alpha[["ERSPS_Oz_DFR"]],1390.62500,2531.25,ERSPS_times_DFR)

low_alpha_delay_average_midOccip <- select_period_average(low_alpha[["ERSPS_midOccip_DFR"]],2531.25,3324.21875,ERSPS_times_DFR)
low_alpha_delay_average_Oz <- select_period_average(low_alpha[["ERSPS_Oz_DFR"]],2531.25,3226.56250,ERSPS_times_DFR)

low_alpha_probe_average_midOccip <- select_period_average(low_alpha[["ERSPS_midOccip_DFR"]],6007.81250,6851.56250,ERSPS_times_DFR)
low_alpha_probe_average_Oz <- select_period_average(low_alpha[["ERSPS_Oz_DFR"]],5910.15625,7000.00000,ERSPS_times_DFR)
high_alpha_cue_average_midOccip <- select_period_average(high_alpha[["ERSPS_midOccip_DFR"]],792.96875,2531.25,ERSPS_times_DFR)
high_alpha_cue_average_Oz <- select_period_average(high_alpha[["ERSPS_Oz_DFR"]],1042.96875,2531.25,ERSPS_times_DFR)

high_alpha_delay_average_midOccip <- select_period_average(high_alpha[["ERSPS_midOccip_DFR"]],2531.25,3078.12500,ERSPS_times_DFR)
high_alpha_delay_average_Oz <- select_period_average(high_alpha[["ERSPS_Oz_DFR"]],2531.25,2976.56250,ERSPS_times_DFR)

high_alpha_late_delay_average_midOccip <- select_period_average(high_alpha[["ERSPS_midOccip_DFR"]],3375.00000,5261.71875,ERSPS_times_DFR)
high_alpha_late_delay_average_Oz <- select_period_average(high_alpha[["ERSPS_Oz_DFR"]],3226.56250,  
                                                          5261.71875,ERSPS_times_DFR)

high_alpha_probe_average_midOccip <- select_period_average(high_alpha[["ERSPS_midOccip_DFR"]],6007.81250,6800.78125,ERSPS_times_DFR)
high_alpha_probe_average_Oz <- select_period_average(high_alpha[["ERSPS_Oz_DFR"]],6058.59375,6851.56250,ERSPS_times_DFR)
t.test(alpha_cue_average_midOccip$load_effect,mu=0)
## 
##  One Sample t-test
## 
## data:  alpha_cue_average_midOccip$load_effect
## t = -10.688, df = 177, p-value < 2.2e-16
## alternative hypothesis: true mean is not equal to 0
## 95 percent confidence interval:
##  -1.2794605 -0.8806336
## sample estimates:
## mean of x 
## -1.080047
t.test(alpha_cue_average_Oz$load_effect,mu=0)
## 
##  One Sample t-test
## 
## data:  alpha_cue_average_Oz$load_effect
## t = -7.5737, df = 189, p-value = 1.565e-12
## alternative hypothesis: true mean is not equal to 0
## 95 percent confidence interval:
##  -0.8895789 -0.5219415
## sample estimates:
##  mean of x 
## -0.7057602
t.test(alpha_delay_average_midOccip$load_effect,mu=0)
## 
##  One Sample t-test
## 
## data:  alpha_delay_average_midOccip$load_effect
## t = -8.1718, df = 177, p-value = 5.61e-14
## alternative hypothesis: true mean is not equal to 0
## 95 percent confidence interval:
##  -1.0746931 -0.6565923
## sample estimates:
##  mean of x 
## -0.8656427
t.test(alpha_delay_average_Oz$load_effect,mu=0)
## 
##  One Sample t-test
## 
## data:  alpha_delay_average_Oz$load_effect
## t = -8.0186, df = 189, p-value = 1.089e-13
## alternative hypothesis: true mean is not equal to 0
## 95 percent confidence interval:
##  -0.8903460 -0.5387768
## sample estimates:
##  mean of x 
## -0.7145614
t.test(alpha_probe_average_midOccip$load_effect,mu=0)
## 
##  One Sample t-test
## 
## data:  alpha_probe_average_midOccip$load_effect
## t = -5.8461, df = 177, p-value = 2.373e-08
## alternative hypothesis: true mean is not equal to 0
## 95 percent confidence interval:
##  -0.9071712 -0.4492800
## sample estimates:
##  mean of x 
## -0.6782256
t.test(alpha_probe_average_Oz$load_effect,mu=0)
## 
##  One Sample t-test
## 
## data:  alpha_probe_average_Oz$load_effect
## t = -7.4267, df = 189, p-value = 3.714e-12
## alternative hypothesis: true mean is not equal to 0
## 95 percent confidence interval:
##  -1.1191573 -0.6494088
## sample estimates:
##  mean of x 
## -0.8842831
ERSP_behav_corr_data <- constructs_fMRI[,c(1,8)]
ERSP_behav_corr_data$LE <- p200_delay_DFR$DFR_Load3_Load1
ERSP_behav_corr_data[,4] <- p200_data[p200_data$PTID %in% constructs_fMRI$PTID, 7]

alpha_data <- Reduce(function(x,y) merge(x,y, by="PTID"),
                     list(alpha_cue_average_midOccip[,c(1,4)], alpha_cue_average_Oz[,c(1,4)],
                          alpha_delay_average_Oz[,c(1,4)],alpha_probe_average_midOccip[,c(1,4)],
                          alpha_probe_average_Oz[,c(1,4)], alpha_cue_average_midOccip[,c(1,2)], 
                          alpha_cue_average_Oz[,c(1,2)]))
## Warning in merge.data.frame(x, y, by = "PTID"): column names 'load_effect.x',
## 'load_effect.y' are duplicated in the result

## Warning in merge.data.frame(x, y, by = "PTID"): column names 'load_effect.x',
## 'load_effect.y' are duplicated in the result

## Warning in merge.data.frame(x, y, by = "PTID"): column names 'load_effect.x',
## 'load_effect.y' are duplicated in the result

## Warning in merge.data.frame(x, y, by = "PTID"): column names 'load_effect.x',
## 'load_effect.y' are duplicated in the result
colnames(alpha_data) <- c("PTID", "cue_midOccip", "cue_Oz", "delay_Oz", "probe_midOccip", "probe_Oz", "cue_midOccip_high", 
                          "cue_Oz_high")

alpha_behav <- merge(ERSP_behav_corr_data,alpha_data, by = "PTID")

for (col in seq.int(5,11)){
  alpha_behav[((alpha_behav[,col] > mean(alpha_behav[,col])+3*sd(alpha_behav[,col])) | 
                 (alpha_behav[,col] < mean(alpha_behav[,col])-3*sd(alpha_behav[,col]))), col] <- NA
}


for (col in seq.int(5,11)){
  print(ggplot(data = alpha_behav, aes_string(x="omnibus_span_no_DFR", y = colnames(alpha_behav)[col]))+
          geom_point()+
          stat_smooth(method="lm")+
          theme_classic()+
          theme(aspect.ratio=1))
  print(colnames(alpha_behav)[col])
  print(cor.test(alpha_behav$omnibus_span_no_DFR, alpha_behav[,col]))
}
## `geom_smooth()` using formula 'y ~ x'
## Warning: Removed 1 rows containing non-finite values (stat_smooth).
## Warning: Removed 1 rows containing missing values (geom_point).

## [1] "cue_midOccip"
## 
##  Pearson's product-moment correlation
## 
## data:  alpha_behav$omnibus_span_no_DFR and alpha_behav[, col]
## t = -1.2174, df = 150, p-value = 0.2253
## alternative hypothesis: true correlation is not equal to 0
## 95 percent confidence interval:
##  -0.25411529  0.06124894
## sample estimates:
##         cor 
## -0.09891628
## `geom_smooth()` using formula 'y ~ x'
## Warning: Removed 1 rows containing non-finite values (stat_smooth).

## Warning: Removed 1 rows containing missing values (geom_point).

## [1] "cue_Oz"
## 
##  Pearson's product-moment correlation
## 
## data:  alpha_behav$omnibus_span_no_DFR and alpha_behav[, col]
## t = 0.45722, df = 150, p-value = 0.6482
## alternative hypothesis: true correlation is not equal to 0
## 95 percent confidence interval:
##  -0.1226234  0.1953461
## sample estimates:
##        cor 
## 0.03730556
## `geom_smooth()` using formula 'y ~ x'
## Warning: Removed 2 rows containing non-finite values (stat_smooth).
## Warning: Removed 2 rows containing missing values (geom_point).

## [1] "delay_Oz"
## 
##  Pearson's product-moment correlation
## 
## data:  alpha_behav$omnibus_span_no_DFR and alpha_behav[, col]
## t = -0.26668, df = 149, p-value = 0.7901
## alternative hypothesis: true correlation is not equal to 0
## 95 percent confidence interval:
##  -0.1809393  0.1383691
## sample estimates:
##         cor 
## -0.02184212
## `geom_smooth()` using formula 'y ~ x'
## Warning: Removed 2 rows containing non-finite values (stat_smooth).

## Warning: Removed 2 rows containing missing values (geom_point).

## [1] "probe_midOccip"
## 
##  Pearson's product-moment correlation
## 
## data:  alpha_behav$omnibus_span_no_DFR and alpha_behav[, col]
## t = -1.8613, df = 149, p-value = 0.06468
## alternative hypothesis: true correlation is not equal to 0
## 95 percent confidence interval:
##  -0.303168319  0.009210906
## sample estimates:
##        cor 
## -0.1507393
## `geom_smooth()` using formula 'y ~ x'
## Warning: Removed 3 rows containing non-finite values (stat_smooth).
## Warning: Removed 3 rows containing missing values (geom_point).

## [1] "probe_Oz"
## 
##  Pearson's product-moment correlation
## 
## data:  alpha_behav$omnibus_span_no_DFR and alpha_behav[, col]
## t = -0.56958, df = 148, p-value = 0.5698
## alternative hypothesis: true correlation is not equal to 0
## 95 percent confidence interval:
##  -0.2054896  0.1143503
## sample estimates:
##         cor 
## -0.04676825
## `geom_smooth()` using formula 'y ~ x'

## [1] "cue_midOccip_high"
## 
##  Pearson's product-moment correlation
## 
## data:  alpha_behav$omnibus_span_no_DFR and alpha_behav[, col]
## t = -0.87343, df = 151, p-value = 0.3838
## alternative hypothesis: true correlation is not equal to 0
## 95 percent confidence interval:
##  -0.22702358  0.08877738
## sample estimates:
##         cor 
## -0.07089951
## `geom_smooth()` using formula 'y ~ x'

## [1] "cue_Oz_high"
## 
##  Pearson's product-moment correlation
## 
## data:  alpha_behav$omnibus_span_no_DFR and alpha_behav[, col]
## t = -0.45729, df = 151, p-value = 0.6481
## alternative hypothesis: true correlation is not equal to 0
## 95 percent confidence interval:
##  -0.1947174  0.1222110
## sample estimates:
##         cor 
## -0.03718832
alphas_for_plot <- list()
betas_for_plot <- list()
low_alphas_for_plot <- list()
high_alphas_for_plot <- list()
thetas_for_plot <- list()
low_gammas_for_plot <- list()
load_list <- c("low_load", "high_load", "load_effect")
ERSPS_list <- list( 
  ERSPS_midOccip_DFR = ERSPS_midOccip_DFR, 
  ERSPS_Oz_DFR = ERSPS_Oz_DFR, 
  ERSPS_Fz_DFR = ERSPS_Fz_DFR)

for (cluster in seq.int(1,2)){
  temp <- list()
  for (load in seq.int(1,3)){
    temp[[load_list[load]]] <- alpha[[cluster]][[load]]
  }
  if (substr(names(alpha)[cluster],nchar(names(alpha)[cluster])-4,nchar(names(alpha)[cluster])-2) == "LCD"){
    alphas_for_plot[[names(ERSPS_list)[cluster]]] <- split_ERPs_into_groups(temp, WM_groups_no_EEG, ERSPS_times_LCD)
  } else{
    alphas_for_plot[[names(ERSPS_list)[cluster]]] <- split_ERPs_into_groups(temp, WM_groups_no_EEG, ERSPS_times_DFR)
  }
}

for (cluster in seq.int(1,2)){
  temp <- list()
  for (load in seq.int(1,3)){
    temp[[load_list[load]]] <- low_alpha[[cluster]][[load]]
  }
  if (substr(names(low_alpha)[cluster],nchar(names(low_alpha)[cluster])-4,nchar(names(low_alpha)[cluster])-2) == "LCD"){
    low_alphas_for_plot[[names(ERSPS_list)[cluster]]] <- split_ERPs_into_groups(temp, WM_groups_no_EEG, ERSPS_times_LCD)
  } else{
    low_alphas_for_plot[[names(ERSPS_list)[cluster]]] <- split_ERPs_into_groups(temp, WM_groups_no_EEG, ERSPS_times_DFR)
  }
}

for (cluster in seq.int(1,2)){
  temp <- list()
  for (load in seq.int(1,3)){
    temp[[load_list[load]]] <- high_alpha[[cluster]][[load]]
  }
  if (substr(names(high_alpha)[cluster],nchar(names(high_alpha)[cluster])-4,nchar(names(high_alpha)[cluster])-2) == "LCD"){
    high_alphas_for_plot[[names(ERSPS_list)[cluster]]] <- split_ERPs_into_groups(temp, WM_groups_no_EEG, ERSPS_times_LCD)
  } else{
    high_alphas_for_plot[[names(ERSPS_list)[cluster]]] <- split_ERPs_into_groups(temp, WM_groups_no_EEG, ERSPS_times_DFR)
  }
}

for (cluster in seq.int(1,2)){
  temp <- list()
  for (load in seq.int(1,3)){
    temp[[load_list[load]]] <- beta[[cluster]][[load]]
  }
  if (substr(names(beta)[cluster],nchar(names(beta)[cluster])-4,nchar(names(beta)[cluster])-2) == "LCD"){
    betas_for_plot[[names(ERSPS_list)[cluster]]] <- split_ERPs_into_groups(temp, WM_groups_no_EEG, ERSPS_times_LCD)
  } else{
    betas_for_plot[[names(ERSPS_list)[cluster]]] <- split_ERPs_into_groups(temp, WM_groups_no_EEG, ERSPS_times_DFR)
  }
}

for (cluster in seq.int(1,3)){
  temp <- list()
  for (load in seq.int(1,3)){
    temp[[load_list[load]]] <- theta[[cluster]][[load]]
  }
  if (substr(names(theta)[cluster],nchar(names(theta)[cluster])-4,nchar(names(theta)[cluster])-2) == "LCD"){
    thetas_for_plot[[names(ERSPS_list)[cluster]]] <- split_ERPs_into_groups(temp, WM_groups, ERSPS_times_LCD)
  } else{
    thetas_for_plot[[names(ERSPS_list)[cluster]]] <- split_ERPs_into_groups(temp, WM_groups, ERSPS_times_DFR)
  }
}


for (cluster in seq.int(1,2)){
  temp <- list()
  for (load in seq.int(1,3)){
    temp[[load_list[load]]] <- low_gamma[[cluster]][[load]]
  }
  if (substr(names(low_gamma)[cluster],nchar(names(low_gamma)[cluster])-4,nchar(names(low_gamma)[cluster])-2) == "LCD"){
    low_gammas_for_plot[[names(ERSPS_list)[cluster]]] <- split_ERPs_into_groups(temp, WM_groups_no_EEG, ERSPS_times_LCD)
  } else{
    low_gammas_for_plot[[names(ERSPS_list)[cluster]]] <- split_ERPs_into_groups(temp, WM_groups_no_EEG, ERSPS_times_DFR)
  }
}

By WM groups

When we split into the working memory capacity groups, we see differences across capacity in the mid occipital cluster during probe period, where we see a more negative load effect in the high capacity group vs the medium capacity group. We also see a significant difference between the low and high capacity subjects in the raw high load power, where the high capacity subjects show more negative power than the low load subjects.

We also can see an inverted U shape during the delay period in the Oz electrode, though it isn’t significant.

split_alphas_plot <- create_TC_for_plot(alphas_for_plot)
split_low_alphas_plot <- create_TC_for_plot(low_alphas_for_plot)
split_high_alphas_plot <- create_TC_for_plot(high_alphas_for_plot)
split_betas_plot <- create_TC_for_plot(betas_for_plot)
split_thetas_plot <- create_TC_for_plot(thetas_for_plot)
split_low_gammas_plot <- create_TC_for_plot(low_gammas_for_plot)

All Alpha

midOccip_DFR_alpha <- paired_freq_plot(split_alphas_plot[["ERSPS_midOccip_DFR"]][["long"]], c("high","low", "load_effect"))

Oz_DFR_alpha <- paired_freq_plot(split_alphas_plot[["ERSPS_Oz_DFR"]][["long"]], c("high","low", "load_effect"))

midOccip_DFR_alpha[[1]] + midOccip_DFR_alpha[[2]]+
  plot_annotation(title="midOccip - alpha during DFR")+
  plot_layout(guides="collect")

Oz_DFR_alpha[[1]] + Oz_DFR_alpha[[2]]+
  plot_annotation(title="Oz - alpha during DFR")+
  plot_layout(guides="collect")

alpha_cue_Oz_DFR_split <- split_into_groups(alpha_cue_average_Oz, WM_groups_no_EEG)
alpha_cue_midOccip_DFR_split <- split_into_groups(alpha_cue_average_midOccip, WM_groups_no_EEG)

alpha_delay_Oz_DFR_split <- split_into_groups(alpha_delay_average_Oz, WM_groups_no_EEG)
alpha_delay_midOccip_DFR_split <- split_into_groups(alpha_delay_average_midOccip, WM_groups_no_EEG)

alpha_probe_Oz_DFR_split <- split_into_groups(alpha_probe_average_Oz, WM_groups_no_EEG)
alpha_probe_midOccip_DFR_split <- split_into_groups(alpha_probe_average_midOccip, WM_groups_no_EEG)

alpha_cue_Oz_DFR_split_prepped <- prep_split_for_bar_plots(alpha_cue_Oz_DFR_split)
alpha_cue_midOccip_DFR_split_prepped <- prep_split_for_bar_plots(alpha_cue_midOccip_DFR_split)


alpha_delay_Oz_DFR_split_prepped <- prep_split_for_bar_plots(alpha_delay_Oz_DFR_split)
alpha_delay_midOccip_DFR_split_prepped <- prep_split_for_bar_plots(alpha_delay_midOccip_DFR_split)


alpha_probe_Oz_DFR_split_prepped <- prep_split_for_bar_plots(alpha_probe_Oz_DFR_split)
alpha_probe_midOccip_DFR_split_prepped <- prep_split_for_bar_plots(alpha_probe_midOccip_DFR_split)
alpha_cue_midOccip_DFR_anova <- merge(alpha_cue_average_midOccip,WM_to_merge, by="PTID")
alpha_delay_midOccip_DFR_anova <- merge(alpha_delay_average_midOccip,WM_to_merge, by="PTID")
alpha_probe_midOccip_DFR_anova <- merge(alpha_probe_average_midOccip,WM_to_merge, by="PTID")

alpha_cue_Oz_DFR_anova <- merge(alpha_cue_average_Oz,WM_to_merge, by="PTID")
alpha_delay_Oz_DFR_anova <- merge(alpha_delay_average_Oz,WM_to_merge, by="PTID")
alpha_probe_Oz_DFR_anova <- merge(alpha_probe_average_Oz,WM_to_merge, by="PTID")
alpha_cue_Oz_DFR_split_prepped[["melt_data"]] %>% 
  filter(variable=="load_effect") %>% 
  mutate(level = factor(level, levels =c("low","med","high"))) %>%
  ggplot()+
  geom_bar(aes(x=level,y=Means),stat="identity")+
  geom_errorbar(aes(x=level,ymin=Means-SE, ymax=Means+SE), width=0.2)+
  ggtitle("Cue")+ 
  xlab("WMC")+
  ylab("ERP amplitude LE")+
  theme_classic()+
  theme(aspect.ratio = 1) -> alpha_cue_Oz_LE

alpha_cue_midOccip_DFR_split_prepped[["melt_data"]] %>% 
  filter(variable=="load_effect") %>% 
  mutate(level = factor(level, levels =c("low","med","high"))) %>%
  ggplot()+
  geom_bar(aes(x=level,y=Means),stat="identity")+
  geom_errorbar(aes(x=level,ymin=Means-SE, ymax=Means+SE), width=0.2)+
  ggtitle("Cue")+ 
  xlab("WMC")+
  ylab("ERP amplitude LE")+
  theme_classic()+
  theme(aspect.ratio = 1) -> alpha_cue_midOccip_LE

alpha_delay_Oz_DFR_split_prepped[["melt_data"]] %>% 
  filter(variable=="load_effect") %>% 
  mutate(level = factor(level, levels =c("low","med","high"))) %>%
  ggplot()+
  geom_bar(aes(x=level,y=Means),stat="identity")+
  geom_errorbar(aes(x=level,ymin=Means-SE, ymax=Means+SE), width=0.2)+
  ggtitle("Delay")+ 
  xlab("WMC")+
  ylab("ERP amplitude LE")+
  theme_classic()+
  theme(aspect.ratio = 1) -> alpha_delay_Oz_LE

alpha_delay_midOccip_DFR_split_prepped[["melt_data"]] %>% 
  filter(variable=="load_effect") %>% 
  mutate(level = factor(level, levels =c("low","med","high"))) %>%
  ggplot()+
  geom_bar(aes(x=level,y=Means),stat="identity")+
  geom_errorbar(aes(x=level,ymin=Means-SE, ymax=Means+SE), width=0.2)+
  ggtitle("Delay")+ 
  xlab("WMC")+
  ylab("ERP amplitude LE")+
  theme_classic()+
  theme(aspect.ratio = 1) -> alpha_delay_midOccip_LE

alpha_probe_Oz_DFR_split_prepped[["melt_data"]] %>% 
  filter(variable=="load_effect") %>% 
  mutate(level = factor(level, levels =c("low","med","high"))) %>%
  ggplot()+
  geom_bar(aes(x=level,y=Means),stat="identity")+
  geom_errorbar(aes(x=level,ymin=Means-SE, ymax=Means+SE), width=0.2)+
  ggtitle("Probe")+ 
  xlab("WMC")+
  ylab("ERP amplitude LE")+
  theme_classic()+
  theme(aspect.ratio = 1) -> alpha_probe_Oz_LE

alpha_probe_midOccip_DFR_split_prepped[["melt_data"]] %>% 
  filter(variable=="load_effect") %>% 
  mutate(level = factor(level, levels =c("low","med","high"))) %>%
  ggplot()+
  geom_bar(aes(x=level,y=Means),stat="identity")+
  geom_errorbar(aes(x=level,ymin=Means-SE, ymax=Means+SE), width=0.2)+
  ggtitle("Probe")+ 
  xlab("WMC")+
  ylab("ERP amplitude LE")+
  theme_classic()+
  theme(aspect.ratio = 1) -> alpha_probe_midOccip_LE

alpha_cue_Oz_LE + alpha_delay_Oz_LE + alpha_probe_Oz_LE+
  plot_annotation(title="Oz electrode alpha frequency Load Effect during DFR")

alpha_cue_midOccip_LE + alpha_delay_midOccip_LE + alpha_probe_midOccip_LE+
  plot_annotation(title="midOccip cluster alpha frequency Load Effect during DFR")

alpha_cue_midOccip.aov <- aov(load_effect ~ level, data = alpha_cue_midOccip_DFR_anova)
print("alpha - cue midOccip")
## [1] "alpha - cue midOccip"
print(summary(alpha_cue_midOccip.aov))
##              Df Sum Sq Mean Sq F value Pr(>F)
## level         2   2.34   1.169   0.626  0.536
## Residuals   148 276.20   1.866
alpha_delay_midOccip.aov <- aov(load_effect ~ level, data = alpha_delay_midOccip_DFR_anova)
print("alpha - delay midOccip")
## [1] "alpha - delay midOccip"
print(summary(alpha_delay_midOccip.aov))
##              Df Sum Sq Mean Sq F value Pr(>F)
## level         2   2.76   1.381    0.73  0.484
## Residuals   148 280.08   1.892
alpha_probe_midOccip.aov <- aov(load_effect ~ level, data = alpha_probe_midOccip_DFR_anova)
print("alpha - probe midOccip")
## [1] "alpha - probe midOccip"
alpha_cue_Oz.aov <- aov(load_effect ~ level, data = alpha_cue_Oz_DFR_anova)
print("alpha - cue Oz")
## [1] "alpha - cue Oz"
print(summary(alpha_cue_Oz.aov))
##              Df Sum Sq Mean Sq F value Pr(>F)
## level         2   0.19  0.0961   0.059  0.943
## Residuals   158 257.46  1.6295
alpha_delay_Oz.aov <- aov(load_effect ~ level, data = alpha_delay_Oz_DFR_anova)
print("alpha - delay Oz")
## [1] "alpha - delay Oz"
print(summary(alpha_delay_Oz.aov))
##              Df Sum Sq Mean Sq F value Pr(>F)
## level         2   1.26  0.6299   0.463   0.63
## Residuals   158 214.80  1.3595

Low alpha

midOccip_DFR_low_alpha <- paired_freq_plot(split_low_alphas_plot[["ERSPS_midOccip_DFR"]][["long"]], c("high","low", "load_effect"))

Oz_DFR_low_alpha <- paired_freq_plot(split_low_alphas_plot[["ERSPS_Oz_DFR"]][["long"]], c("high","low", "load_effect"))

midOccip_DFR_low_alpha[[1]] + midOccip_DFR_low_alpha[[2]]+
  plot_annotation(title="midOccip - low_alpha during DFR")+
  plot_layout(guides="collect")

Oz_DFR_low_alpha[[1]] + Oz_DFR_low_alpha[[2]]+
  plot_annotation(title="Oz - low_alpha during DFR")+
  plot_layout(guides="collect")

low_alpha_cue_Oz_DFR_split <- split_into_groups(low_alpha_cue_average_Oz, WM_groups_no_EEG)
low_alpha_cue_midOccip_DFR_split <- split_into_groups(low_alpha_cue_average_midOccip, WM_groups_no_EEG)

low_alpha_delay_Oz_DFR_split <- split_into_groups(low_alpha_delay_average_Oz, WM_groups_no_EEG)
low_alpha_delay_midOccip_DFR_split <- split_into_groups(low_alpha_delay_average_midOccip, WM_groups_no_EEG)

low_alpha_probe_Oz_DFR_split <- split_into_groups(low_alpha_probe_average_Oz, WM_groups_no_EEG)
low_alpha_probe_midOccip_DFR_split <- split_into_groups(low_alpha_probe_average_midOccip, WM_groups_no_EEG)

low_alpha_cue_Oz_DFR_split_prepped <- prep_split_for_bar_plots(low_alpha_cue_Oz_DFR_split)
low_alpha_cue_midOccip_DFR_split_prepped <- prep_split_for_bar_plots(low_alpha_cue_midOccip_DFR_split)


low_alpha_delay_Oz_DFR_split_prepped <- prep_split_for_bar_plots(low_alpha_delay_Oz_DFR_split)
low_alpha_delay_midOccip_DFR_split_prepped <- prep_split_for_bar_plots(low_alpha_delay_midOccip_DFR_split)


low_alpha_probe_Oz_DFR_split_prepped <- prep_split_for_bar_plots(low_alpha_probe_Oz_DFR_split)
low_alpha_probe_midOccip_DFR_split_prepped <- prep_split_for_bar_plots(low_alpha_probe_midOccip_DFR_split)
low_alpha_cue_midOccip_DFR_anova <- merge(low_alpha_cue_average_midOccip,WM_to_merge, by="PTID")
low_alpha_delay_midOccip_DFR_anova <- merge(low_alpha_delay_average_midOccip,WM_to_merge, by="PTID")
low_alpha_probe_midOccip_DFR_anova <- merge(low_alpha_probe_average_midOccip,WM_to_merge, by="PTID")

low_alpha_cue_Oz_DFR_anova <- merge(low_alpha_cue_average_Oz,WM_to_merge, by="PTID")
low_alpha_delay_Oz_DFR_anova <- merge(low_alpha_delay_average_Oz,WM_to_merge, by="PTID")
low_alpha_probe_Oz_DFR_anova <- merge(low_alpha_probe_average_Oz,WM_to_merge, by="PTID")
low_alpha_cue_midOccip_DFR_split_prepped[["melt_data"]] %>% 
  filter(variable=="high_load") %>% 
  mutate(level = factor(level, levels =c("low","med","high"))) %>%
  ggplot()+
  geom_bar(aes(x=level,y=Means),stat="identity")+
  geom_errorbar(aes(x=level,ymin=Means-SE, ymax=Means+SE), width=0.2)+
  ggtitle("Cue")+ 
  xlab("WMC")+
  ylab("ERP amplitude LE")+
  theme_classic()+
  theme(aspect.ratio = 1) 

summary(rlm(omnibus_span_no_DFR ~ high_load, data = merge(low_alpha_cue_midOccip_DFR_anova, constructs_fMRI)))
## 
## Call: rlm(formula = omnibus_span_no_DFR ~ high_load, data = merge(low_alpha_cue_midOccip_DFR_anova, 
##     constructs_fMRI))
## Residuals:
##       Min        1Q    Median        3Q       Max 
## -1.789037 -0.391251 -0.001902  0.351991  1.612029 
## 
## Coefficients:
##             Value   Std. Error t value
## (Intercept)  0.0645  0.0526     1.2275
## high_load   -0.0318  0.0253    -1.2551
## 
## Residual standard error: 0.5538 on 149 degrees of freedom
high_midOccip_cue_low_alpha.aov <- aov(high_load ~ level, data = merge(low_alpha_cue_midOccip_DFR_anova, constructs_fMRI))
summary(high_midOccip_cue_low_alpha.aov)
##              Df Sum Sq Mean Sq F value Pr(>F)
## level         2    7.5   3.735    1.03   0.36
## Residuals   148  536.6   3.626
TukeyHSD(high_midOccip_cue_low_alpha.aov)
##   Tukey multiple comparisons of means
##     95% family-wise confidence level
## 
## Fit: aov(formula = high_load ~ level, data = merge(low_alpha_cue_midOccip_DFR_anova, constructs_fMRI))
## 
## $level
##                diff        lwr       upr     p adj
## low-high  0.5157093 -0.3777173 1.4091360 0.3610819
## med-high  0.3929841 -0.5004426 1.2864108 0.5520278
## med-low  -0.1227252 -1.0335016 0.7880512 0.9454661
low_alpha_cue_Oz_DFR_split_prepped[["melt_data"]] %>% 
  filter(variable=="load_effect") %>% 
  mutate(level = factor(level, levels =c("low","med","high"))) %>%
  ggplot()+
  geom_bar(aes(x=level,y=Means),stat="identity")+
  geom_errorbar(aes(x=level,ymin=Means-SE, ymax=Means+SE), width=0.2)+
  ggtitle("Cue")+ 
  xlab("WMC")+
  ylab("ERP amplitude LE")+
  theme_classic()+
  theme(aspect.ratio = 1) -> low_alpha_cue_Oz_LE

low_alpha_cue_midOccip_DFR_split_prepped[["melt_data"]] %>% 
  filter(variable=="load_effect") %>% 
  mutate(level = factor(level, levels =c("low","med","high"))) %>%
  ggplot()+
  geom_bar(aes(x=level,y=Means),stat="identity")+
  geom_errorbar(aes(x=level,ymin=Means-SE, ymax=Means+SE), width=0.2)+
  ggtitle("Cue")+ 
  xlab("WMC")+
  ylab("ERP amplitude LE")+
  theme_classic()+
  theme(aspect.ratio = 1) -> low_alpha_cue_midOccip_LE

low_alpha_delay_Oz_DFR_split_prepped[["melt_data"]] %>% 
  filter(variable=="load_effect") %>% 
  mutate(level = factor(level, levels =c("low","med","high"))) %>%
  ggplot()+
  geom_bar(aes(x=level,y=Means),stat="identity")+
  geom_errorbar(aes(x=level,ymin=Means-SE, ymax=Means+SE), width=0.2)+
  ggtitle("Delay")+ 
  xlab("WMC")+
  ylab("ERP amplitude LE")+
  theme_classic()+
  theme(aspect.ratio = 1) -> low_alpha_delay_Oz_LE

low_alpha_delay_midOccip_DFR_split_prepped[["melt_data"]] %>% 
  filter(variable=="load_effect") %>% 
  mutate(level = factor(level, levels =c("low","med","high"))) %>%
  ggplot()+
  geom_bar(aes(x=level,y=Means),stat="identity")+
  geom_errorbar(aes(x=level,ymin=Means-SE, ymax=Means+SE), width=0.2)+
  ggtitle("Delay")+ 
  xlab("WMC")+
  ylab("ERP amplitude LE")+
  theme_classic()+
  theme(aspect.ratio = 1) -> low_alpha_delay_midOccip_LE

low_alpha_probe_Oz_DFR_split_prepped[["melt_data"]] %>% 
  filter(variable=="load_effect") %>% 
  mutate(level = factor(level, levels =c("low","med","high"))) %>%
  ggplot()+
  geom_bar(aes(x=level,y=Means),stat="identity")+
  geom_errorbar(aes(x=level,ymin=Means-SE, ymax=Means+SE), width=0.2)+
  ggtitle("Probe")+ 
  xlab("WMC")+
  ylab("ERP amplitude LE")+
  theme_classic()+
  theme(aspect.ratio = 1) -> low_alpha_probe_Oz_LE

low_alpha_probe_midOccip_DFR_split_prepped[["melt_data"]] %>% 
  filter(variable=="load_effect") %>% 
  mutate(level = factor(level, levels =c("low","med","high"))) %>%
  ggplot()+
  geom_bar(aes(x=level,y=Means),stat="identity")+
  geom_errorbar(aes(x=level,ymin=Means-SE, ymax=Means+SE), width=0.2)+
  ggtitle("Probe")+ 
  xlab("WMC")+
  ylab("ERP amplitude LE")+
  theme_classic()+
  theme(aspect.ratio = 1) -> low_alpha_probe_midOccip_LE

low_alpha_cue_Oz_LE + low_alpha_delay_Oz_LE + low_alpha_probe_Oz_LE+
  plot_annotation(title="Oz electrode low_alpha frequency Load Effect during DFR")

low_alpha_cue_midOccip_LE + low_alpha_delay_midOccip_LE + low_alpha_probe_midOccip_LE+
  plot_annotation(title="midOccip cluster low_alpha frequency Load Effect during DFR")

low_alpha_cue_midOccip.aov <- aov(load_effect ~ level, data = low_alpha_cue_midOccip_DFR_anova)
print("low_alpha - cue midOccip")
## [1] "low_alpha - cue midOccip"
print(summary(low_alpha_cue_midOccip.aov))
##              Df Sum Sq Mean Sq F value Pr(>F)
## level         2    4.2   2.089   0.794  0.454
## Residuals   148  389.4   2.631
low_alpha_delay_midOccip.aov <- aov(load_effect ~ level, data = low_alpha_delay_midOccip_DFR_anova)
print("low_alpha - delay midOccip")
## [1] "low_alpha - delay midOccip"
print(summary(low_alpha_delay_midOccip.aov))
##              Df Sum Sq Mean Sq F value Pr(>F)
## level         2    4.9   2.446   0.993  0.373
## Residuals   148  364.5   2.463
low_alpha_probe_midOccip.aov <- aov(load_effect ~ level, data = low_alpha_probe_midOccip_DFR_anova)
print("low_alpha - probe midOccip")
## [1] "low_alpha - probe midOccip"
low_alpha_cue_Oz.aov <- aov(load_effect ~ level, data = low_alpha_cue_Oz_DFR_anova)
print("low_alpha - cue Oz")
## [1] "low_alpha - cue Oz"
print(summary(low_alpha_cue_Oz.aov))
##              Df Sum Sq Mean Sq F value Pr(>F)
## level         2    0.2   0.081   0.038  0.963
## Residuals   158  340.9   2.158
low_alpha_delay_Oz.aov <- aov(load_effect ~ level, data = low_alpha_delay_Oz_DFR_anova)
print("low_alpha - delay Oz")
## [1] "low_alpha - delay Oz"
print(summary(low_alpha_delay_Oz.aov))
##              Df Sum Sq Mean Sq F value Pr(>F)
## level         2   2.42   1.212   0.731  0.483
## Residuals   158 262.00   1.658

High alpha

midOccip_DFR_high_alpha <- paired_freq_plot(split_high_alphas_plot[["ERSPS_midOccip_DFR"]][["long"]], c("high","low", "load_effect"))

Oz_DFR_high_alpha <- paired_freq_plot(split_high_alphas_plot[["ERSPS_Oz_DFR"]][["long"]], c("high","low", "load_effect"))

midOccip_DFR_high_alpha[[1]] + midOccip_DFR_high_alpha[[2]]+
  plot_annotation(title="midOccip - high_alpha during DFR")+
  plot_layout(guides="collect")

Oz_DFR_high_alpha[[1]] + Oz_DFR_high_alpha[[2]]+
  plot_annotation(title="Oz - high_alpha during DFR")+
  plot_layout(guides="collect")

high_alpha_cue_Oz_DFR_split <- split_into_groups(high_alpha_cue_average_Oz, WM_groups_no_EEG)
high_alpha_cue_midOccip_DFR_split <- split_into_groups(high_alpha_cue_average_midOccip, WM_groups_no_EEG)

high_alpha_delay_Oz_DFR_split <- split_into_groups(high_alpha_delay_average_Oz, WM_groups_no_EEG)
high_alpha_delay_midOccip_DFR_split <- split_into_groups(high_alpha_delay_average_midOccip, WM_groups_no_EEG)

high_alpha_late_delay_Oz_DFR_split <- split_into_groups(high_alpha_late_delay_average_Oz, WM_groups_no_EEG)
high_alpha_late_delay_midOccip_DFR_split <- split_into_groups(high_alpha_late_delay_average_midOccip, WM_groups_no_EEG)

high_alpha_probe_Oz_DFR_split <- split_into_groups(high_alpha_probe_average_Oz, WM_groups_no_EEG)
high_alpha_probe_midOccip_DFR_split <- split_into_groups(high_alpha_probe_average_midOccip, WM_groups_no_EEG)

high_alpha_cue_Oz_DFR_split_prepped <- prep_split_for_bar_plots(high_alpha_cue_Oz_DFR_split)
high_alpha_cue_midOccip_DFR_split_prepped <- prep_split_for_bar_plots(high_alpha_cue_midOccip_DFR_split)

high_alpha_delay_Oz_DFR_split_prepped <- prep_split_for_bar_plots(high_alpha_delay_Oz_DFR_split)
high_alpha_delay_midOccip_DFR_split_prepped <- prep_split_for_bar_plots(high_alpha_delay_midOccip_DFR_split)

high_alpha_late_delay_Oz_DFR_split_prepped <- prep_split_for_bar_plots(high_alpha_late_delay_Oz_DFR_split)
high_alpha_late_delay_midOccip_DFR_split_prepped <- prep_split_for_bar_plots(high_alpha_late_delay_midOccip_DFR_split)

high_alpha_probe_Oz_DFR_split_prepped <- prep_split_for_bar_plots(high_alpha_probe_Oz_DFR_split)
high_alpha_probe_midOccip_DFR_split_prepped <- prep_split_for_bar_plots(high_alpha_probe_midOccip_DFR_split)
high_alpha_cue_midOccip_DFR_anova <- merge(high_alpha_cue_average_midOccip,WM_to_merge, by="PTID")
high_alpha_delay_midOccip_DFR_anova <- merge(high_alpha_delay_average_midOccip,WM_to_merge, by="PTID")
high_alpha_late_delay_midOccip_DFR_anova <- merge(high_alpha_late_delay_average_midOccip,WM_to_merge, by="PTID")
high_alpha_probe_midOccip_DFR_anova <- merge(high_alpha_probe_average_midOccip,WM_to_merge, by="PTID")

high_alpha_cue_Oz_DFR_anova <- merge(high_alpha_cue_average_Oz,WM_to_merge, by="PTID")
high_alpha_delay_Oz_DFR_anova <- merge(high_alpha_delay_average_Oz,WM_to_merge, by="PTID")
high_alpha_late_delay_Oz_DFR_anova <- merge(high_alpha_late_delay_average_Oz,WM_to_merge, by="PTID")
high_alpha_probe_Oz_DFR_anova <- merge(high_alpha_probe_average_Oz,WM_to_merge, by="PTID")
high_alpha_cue_midOccip_DFR_split_prepped[["melt_data"]] %>% 
  filter(variable=="high_load") %>% 
  mutate(level = factor(level, levels =c("low","med","high"))) %>%
  ggplot()+
  geom_bar(aes(x=level,y=Means),stat="identity")+
  geom_errorbar(aes(x=level,ymin=Means-SE, ymax=Means+SE), width=0.2)+
  ggtitle("Cue")+ 
  xlab("WMC")+
  ylab("ERP amplitude LE")+
  theme_classic()+
  theme(aspect.ratio = 1) 

summary(rlm(omnibus_span_no_DFR ~ high_load, data = merge(high_alpha_cue_midOccip_DFR_anova, constructs_fMRI)))
## 
## Call: rlm(formula = omnibus_span_no_DFR ~ high_load, data = merge(high_alpha_cue_midOccip_DFR_anova, 
##     constructs_fMRI))
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -1.76146 -0.39134 -0.01895  0.35675  1.53538 
## 
## Coefficients:
##             Value   Std. Error t value
## (Intercept)  0.0690  0.0586     1.1777
## high_load   -0.0192  0.0244    -0.7834
## 
## Residual standard error: 0.5385 on 149 degrees of freedom
high_midOccip_cue_high_alpha.aov <- aov(high_load ~ level, data = merge(high_alpha_cue_midOccip_DFR_anova, constructs_fMRI))
summary(high_midOccip_cue_high_alpha.aov)
##              Df Sum Sq Mean Sq F value Pr(>F)
## level         2    5.2   2.588    0.62  0.539
## Residuals   148  618.1   4.176
TukeyHSD(high_midOccip_cue_high_alpha.aov)
##   Tukey multiple comparisons of means
##     95% family-wise confidence level
## 
## Fit: aov(formula = high_load ~ level, data = merge(high_alpha_cue_midOccip_DFR_anova, constructs_fMRI))
## 
## $level
##                 diff        lwr       upr     p adj
## low-high  0.41760655 -0.5412321 1.3764452 0.5584483
## med-high  0.34979926 -0.6090394 1.3086380 0.6639771
## med-low  -0.06780728 -1.0452659 0.9096514 0.9852408
high_alpha_cue_Oz_DFR_split_prepped[["melt_data"]] %>% 
  filter(variable=="load_effect") %>% 
  mutate(level = factor(level, levels =c("low","med","high"))) %>%
  ggplot()+
  geom_bar(aes(x=level,y=Means),stat="identity")+
  geom_errorbar(aes(x=level,ymin=Means-SE, ymax=Means+SE), width=0.2)+
  ggtitle("Cue")+ 
  xlab("WMC")+
  ylab("ERP amplitude LE")+
  theme_classic()+
  theme(aspect.ratio = 1) -> high_alpha_cue_Oz_LE

high_alpha_cue_midOccip_DFR_split_prepped[["melt_data"]] %>% 
  filter(variable=="load_effect") %>% 
  mutate(level = factor(level, levels =c("low","med","high"))) %>%
  ggplot()+
  geom_bar(aes(x=level,y=Means),stat="identity")+
  geom_errorbar(aes(x=level,ymin=Means-SE, ymax=Means+SE), width=0.2)+
  ggtitle("Cue")+ 
  xlab("WMC")+
  ylab("ERP amplitude LE")+
  theme_classic()+
  theme(aspect.ratio = 1) -> high_alpha_cue_midOccip_LE

high_alpha_delay_Oz_DFR_split_prepped[["melt_data"]] %>% 
  filter(variable=="load_effect") %>% 
  mutate(level = factor(level, levels =c("low","med","high"))) %>%
  ggplot()+
  geom_bar(aes(x=level,y=Means),stat="identity")+
  geom_errorbar(aes(x=level,ymin=Means-SE, ymax=Means+SE), width=0.2)+
  ggtitle("Delay")+ 
  xlab("WMC")+
  ylab("ERP amplitude LE")+
  theme_classic()+
  theme(aspect.ratio = 1) -> high_alpha_delay_Oz_LE

high_alpha_delay_midOccip_DFR_split_prepped[["melt_data"]] %>% 
  filter(variable=="load_effect") %>% 
  mutate(level = factor(level, levels =c("low","med","high"))) %>%
  ggplot()+
  geom_bar(aes(x=level,y=Means),stat="identity")+
  geom_errorbar(aes(x=level,ymin=Means-SE, ymax=Means+SE), width=0.2)+
  ggtitle("Delay")+ 
  xlab("WMC")+
  ylab("ERP amplitude LE")+
  theme_classic()+
  theme(aspect.ratio = 1) -> high_alpha_delay_midOccip_LE

high_alpha_late_delay_Oz_DFR_split_prepped[["melt_data"]] %>% 
  filter(variable=="load_effect") %>% 
  mutate(level = factor(level, levels =c("low","med","high"))) %>%
  ggplot()+
  geom_bar(aes(x=level,y=Means),stat="identity")+
  geom_errorbar(aes(x=level,ymin=Means-SE, ymax=Means+SE), width=0.2)+
  ggtitle("Late Delay - Oz")+ 
  xlab("WMC")+
  ylab("ERP amplitude LE")+
  theme_classic()+
  theme(aspect.ratio = 1) -> high_alpha_late_delay_Oz_LE

high_alpha_late_delay_midOccip_DFR_split_prepped[["melt_data"]] %>% 
  filter(variable=="load_effect") %>% 
  mutate(level = factor(level, levels =c("low","med","high"))) %>%
  ggplot()+
  geom_bar(aes(x=level,y=Means),stat="identity")+
  geom_errorbar(aes(x=level,ymin=Means-SE, ymax=Means+SE), width=0.2)+
  ggtitle("Late Delay - Mid Occipital")+ 
  xlab("WMC")+
  ylab("ERP amplitude LE")+
  theme_classic()+
  theme(aspect.ratio = 1) -> high_alpha_late_delay_midOccip_LE

high_alpha_probe_Oz_DFR_split_prepped[["melt_data"]] %>% 
  filter(variable=="load_effect") %>% 
  mutate(level = factor(level, levels =c("low","med","high"))) %>%
  ggplot()+
  geom_bar(aes(x=level,y=Means),stat="identity")+
  geom_errorbar(aes(x=level,ymin=Means-SE, ymax=Means+SE), width=0.2)+
  ggtitle("Probe")+ 
  xlab("WMC")+
  ylab("ERP amplitude LE")+
  theme_classic()+
  theme(aspect.ratio = 1) -> high_alpha_probe_Oz_LE

high_alpha_probe_midOccip_DFR_split_prepped[["melt_data"]] %>% 
  filter(variable=="load_effect") %>% 
  mutate(level = factor(level, levels =c("low","med","high"))) %>%
  ggplot()+
  geom_bar(aes(x=level,y=Means),stat="identity")+
  geom_errorbar(aes(x=level,ymin=Means-SE, ymax=Means+SE), width=0.2)+
  ggtitle("Probe")+ 
  xlab("WMC")+
  ylab("ERP amplitude LE")+
  theme_classic()+
  theme(aspect.ratio = 1) -> high_alpha_probe_midOccip_LE

high_alpha_cue_Oz_LE + high_alpha_delay_Oz_LE + high_alpha_probe_Oz_LE+
  plot_annotation(title="Oz electrode high alpha frequency Load Effect during DFR")

high_alpha_late_delay_Oz_LE

high_alpha_cue_midOccip_LE + high_alpha_delay_midOccip_LE + high_alpha_probe_midOccip_LE+
  plot_annotation(title="midOccip cluster high alpha frequency Load Effect during DFR")

high_alpha_late_delay_midOccip_LE

high_alpha_cue_midOccip.aov <- aov(load_effect ~ level, data = high_alpha_cue_midOccip_DFR_anova)
print("high_alpha - cue midOccip")
## [1] "high_alpha - cue midOccip"
print(summary(high_alpha_cue_midOccip.aov))
##              Df Sum Sq Mean Sq F value Pr(>F)
## level         2   1.34  0.6685   0.392  0.676
## Residuals   148 252.38  1.7052
high_alpha_delay_midOccip.aov <- aov(load_effect ~ level, data = high_alpha_delay_midOccip_DFR_anova)
print("high_alpha - delay midOccip")
## [1] "high_alpha - delay midOccip"
print(summary(high_alpha_delay_midOccip.aov))
##              Df Sum Sq Mean Sq F value Pr(>F)
## level         2   1.78  0.8877   0.488  0.615
## Residuals   148 269.17  1.8187
high_alpha_late_delay_midOccip.aov <- aov(load_effect ~ level, data = high_alpha_late_delay_midOccip_DFR_anova)
print("high_alpha - late delay midOccip")
## [1] "high_alpha - late delay midOccip"
print(summary(high_alpha_late_delay_midOccip.aov))
##              Df Sum Sq Mean Sq F value Pr(>F)
## level         2   2.89   1.443   0.879  0.417
## Residuals   148 243.06   1.642
high_alpha_probe_midOccip.aov <- aov(load_effect ~ level, data = high_alpha_probe_midOccip_DFR_anova)
print("high_alpha - probe midOccip")
## [1] "high_alpha - probe midOccip"
print(summary(high_alpha_probe_midOccip.aov))
##              Df Sum Sq Mean Sq F value Pr(>F)
## level         2    5.8   2.884   1.202  0.303
## Residuals   148  355.1   2.399
high_alpha_cue_Oz.aov <- aov(load_effect ~ level, data = high_alpha_cue_Oz_DFR_anova)
print("high_alpha - cue Oz")
## [1] "high_alpha - cue Oz"
print(summary(high_alpha_cue_Oz.aov))
##              Df Sum Sq Mean Sq F value Pr(>F)
## level         2   0.69  0.3433   0.192  0.826
## Residuals   158 282.80  1.7899
high_alpha_delay_Oz.aov <- aov(load_effect ~ level, data = high_alpha_delay_Oz_DFR_anova)
print("high_alpha - delay Oz")
## [1] "high_alpha - delay Oz"
print(summary(high_alpha_delay_Oz.aov))
##              Df Sum Sq Mean Sq F value Pr(>F)
## level         2   1.35  0.6732   0.402   0.67
## Residuals   158 264.69  1.6753
high_alpha_late_delay_Oz.aov <- aov(load_effect ~ level, data = high_alpha_late_delay_Oz_DFR_anova)
print("high_alpha - late delay Oz")
## [1] "high_alpha - late delay Oz"
print(summary(high_alpha_late_delay_Oz.aov))
##              Df Sum Sq Mean Sq F value Pr(>F)
## level         2   0.71  0.3552   0.243  0.784
## Residuals   158 230.52  1.4590
high_alpha_late_delay_Oz.aov <- aov(load_effect ~ level, data = high_alpha_late_delay_Oz_DFR_anova)
print("high_alpha - late delay Oz")
## [1] "high_alpha - late delay Oz"
print(summary(high_alpha_late_delay_Oz.aov))
##              Df Sum Sq Mean Sq F value Pr(>F)
## level         2   0.71  0.3552   0.243  0.784
## Residuals   158 230.52  1.4590

Beta

All Subjects

Overall, we see differences in load effects during cue and probe in all electrodes (low > high) and in delay during mid occipital and Oz (high > low).

beta_plot_list[["ERSPS_midOccip_DFR"]][["indiv_loads"]] + beta_plot_list[["ERSPS_midOccip_DFR"]][["LE"]] +
  plot_annotation(title="midOccip - beta during DFR")

beta_plot_list[["ERSPS_Oz_DFR"]][["indiv_loads"]] + beta_plot_list[["ERSPS_Oz_DFR"]][["LE"]] +
  plot_annotation(title="Oz - beta during DFR")

beta_mid_occip_times <- time_sig_load_effects(beta[["ERSPS_midOccip_DFR"]][["load_effect"]], ERSPS_times_DFR)
beta_Oz_times <- time_sig_load_effects(beta[["ERSPS_Oz_DFR"]][["load_effect"]], ERSPS_times_DFR)
beta_cue_average_midOccip <- select_period_average(beta[["ERSPS_midOccip_DFR"]],890.62500,2531.25,ERSPS_times_DFR)
beta_cue_average_Oz <- select_period_average(beta[["ERSPS_Oz_DFR"]],1089.84375,2531.25,ERSPS_times_DFR)

beta_delay_average_midOccip <- select_period_average(beta[["ERSPS_midOccip_DFR"]],2531.25,3128.90625,ERSPS_times_DFR)
beta_delay_average_Oz <- select_period_average(beta[["ERSPS_Oz_DFR"]],2531.25,2878.90625,ERSPS_times_DFR)

beta_probe_average_midOccip <- select_period_average(beta[["ERSPS_midOccip_DFR"]],5757.81250,6800.78125,ERSPS_times_DFR)
beta_probe_average_Oz <- select_period_average(beta[["ERSPS_Oz_DFR"]],6007.81250,6800.78125,ERSPS_times_DFR)
t.test(beta_cue_average_midOccip$load_effect,mu=0)
## 
##  One Sample t-test
## 
## data:  beta_cue_average_midOccip$load_effect
## t = -8.432, df = 177, p-value = 1.159e-14
## alternative hypothesis: true mean is not equal to 0
## 95 percent confidence interval:
##  -0.8010191 -0.4971839
## sample estimates:
##  mean of x 
## -0.6491015
t.test(beta_cue_average_Oz$load_effect,mu=0)
## 
##  One Sample t-test
## 
## data:  beta_cue_average_Oz$load_effect
## t = -6.4893, df = 189, p-value = 7.375e-10
## alternative hypothesis: true mean is not equal to 0
## 95 percent confidence interval:
##  -0.7004727 -0.3738916
## sample estimates:
##  mean of x 
## -0.5371821
t.test(beta_delay_average_midOccip$load_effect,mu=0)
## 
##  One Sample t-test
## 
## data:  beta_delay_average_midOccip$load_effect
## t = -5.4057, df = 177, p-value = 2.066e-07
## alternative hypothesis: true mean is not equal to 0
## 95 percent confidence interval:
##  -0.6157004 -0.2863768
## sample estimates:
##  mean of x 
## -0.4510386
t.test(beta_delay_average_Oz$load_effect,mu=0)
## 
##  One Sample t-test
## 
## data:  beta_delay_average_Oz$load_effect
## t = -7.2266, df = 189, p-value = 1.187e-11
## alternative hypothesis: true mean is not equal to 0
## 95 percent confidence interval:
##  -0.779423 -0.445158
## sample estimates:
##  mean of x 
## -0.6122905
t.test(beta_probe_average_midOccip$load_effect,mu=0)
## 
##  One Sample t-test
## 
## data:  beta_probe_average_midOccip$load_effect
## t = -7.7091, df = 177, p-value = 8.774e-13
## alternative hypothesis: true mean is not equal to 0
## 95 percent confidence interval:
##  -0.9328424 -0.5525856
## sample estimates:
## mean of x 
## -0.742714
t.test(beta_probe_average_Oz$load_effect,mu=0)
## 
##  One Sample t-test
## 
## data:  beta_probe_average_Oz$load_effect
## t = -9.446, df = 189, p-value < 2.2e-16
## alternative hypothesis: true mean is not equal to 0
## 95 percent confidence interval:
##  -1.2988818 -0.8501101
## sample estimates:
## mean of x 
## -1.074496
beta_data <- Reduce(function(x,y) merge(x,y, by="PTID"),
                    list(beta_cue_average_midOccip[,c(1,4)], beta_cue_average_Oz[,c(1,4)],
                         beta_delay_average_midOccip[,c(1,4)],beta_delay_average_Oz[,c(1,4)],
                         beta_probe_average_midOccip[,c(1,4)],
                         beta_probe_average_Oz[,c(1,4)], beta_cue_average_midOccip[,c(1,2)],
                         beta_cue_average_midOccip[,c(1,2)]))
## Warning in merge.data.frame(x, y, by = "PTID"): column names 'load_effect.x',
## 'load_effect.y' are duplicated in the result

## Warning in merge.data.frame(x, y, by = "PTID"): column names 'load_effect.x',
## 'load_effect.y' are duplicated in the result
## Warning in merge.data.frame(x, y, by = "PTID"): column names 'load_effect.x',
## 'load_effect.y', 'load_effect.x', 'load_effect.y' are duplicated in the result

## Warning in merge.data.frame(x, y, by = "PTID"): column names 'load_effect.x',
## 'load_effect.y', 'load_effect.x', 'load_effect.y' are duplicated in the result

## Warning in merge.data.frame(x, y, by = "PTID"): column names 'load_effect.x',
## 'load_effect.y', 'load_effect.x', 'load_effect.y' are duplicated in the result
colnames(beta_data) <- c("PTID", "cue_midOccip", "cue_Oz", "delay_midOccip","delay_Oz", "probe_midOccip", "probe_Oz", "high_midOccip_cue", "high_Oz_cue")

beta_behav <- merge(ERSP_behav_corr_data,beta_data, by = "PTID")

for (col in seq.int(5,11)){
  beta_behav[((beta_behav[,col] > mean(beta_behav[,col])+3*sd(beta_behav[,col])) | 
                (beta_behav[,col] < mean(beta_behav[,col])-3*sd(beta_behav[,col]))), col] <- NA
}

for (col in seq.int(5,11)){
  print(ggplot(data = beta_behav, aes_string(x="omnibus_span_no_DFR", y = colnames(beta_behav)[col]))+
          geom_point()+
          stat_smooth(method="lm")+
          theme_classic()+
          theme(aspect.ratio=1))
  print(colnames(beta_behav)[col])
  print(cor.test(beta_behav$omnibus_span_no_DFR, beta_behav[,col]))
  
}
## `geom_smooth()` using formula 'y ~ x'

## [1] "cue_midOccip"
## 
##  Pearson's product-moment correlation
## 
## data:  beta_behav$omnibus_span_no_DFR and beta_behav[, col]
## t = -0.25541, df = 151, p-value = 0.7988
## alternative hypothesis: true correlation is not equal to 0
## 95 percent confidence interval:
##  -0.1788690  0.1383537
## sample estimates:
##         cor 
## -0.02078065
## `geom_smooth()` using formula 'y ~ x'
## Warning: Removed 1 rows containing non-finite values (stat_smooth).
## Warning: Removed 1 rows containing missing values (geom_point).

## [1] "cue_Oz"
## 
##  Pearson's product-moment correlation
## 
## data:  beta_behav$omnibus_span_no_DFR and beta_behav[, col]
## t = -0.048345, df = 150, p-value = 0.9615
## alternative hypothesis: true correlation is not equal to 0
## 95 percent confidence interval:
##  -0.1630455  0.1553510
## sample estimates:
##          cor 
## -0.003947308
## `geom_smooth()` using formula 'y ~ x'
## Warning: Removed 4 rows containing non-finite values (stat_smooth).
## Warning: Removed 4 rows containing missing values (geom_point).

## [1] "delay_midOccip"
## 
##  Pearson's product-moment correlation
## 
## data:  beta_behav$omnibus_span_no_DFR and beta_behav[, col]
## t = -0.33429, df = 147, p-value = 0.7386
## alternative hypothesis: true correlation is not equal to 0
## 95 percent confidence interval:
##  -0.1875300  0.1338319
## sample estimates:
##         cor 
## -0.02756117
## `geom_smooth()` using formula 'y ~ x'

## [1] "delay_Oz"
## 
##  Pearson's product-moment correlation
## 
## data:  beta_behav$omnibus_span_no_DFR and beta_behav[, col]
## t = -0.61987, df = 151, p-value = 0.5363
## alternative hypothesis: true correlation is not equal to 0
## 95 percent confidence interval:
##  -0.2074003  0.1091707
## sample estimates:
##         cor 
## -0.05038019
## `geom_smooth()` using formula 'y ~ x'
## Warning: Removed 2 rows containing non-finite values (stat_smooth).
## Warning: Removed 2 rows containing missing values (geom_point).

## [1] "probe_midOccip"
## 
##  Pearson's product-moment correlation
## 
## data:  beta_behav$omnibus_span_no_DFR and beta_behav[, col]
## t = -0.47641, df = 149, p-value = 0.6345
## alternative hypothesis: true correlation is not equal to 0
## 95 percent confidence interval:
##  -0.1974971  0.1214863
## sample estimates:
##         cor 
## -0.03899893
## `geom_smooth()` using formula 'y ~ x'
## Warning: Removed 3 rows containing non-finite values (stat_smooth).
## Warning: Removed 3 rows containing missing values (geom_point).

## [1] "probe_Oz"
## 
##  Pearson's product-moment correlation
## 
## data:  beta_behav$omnibus_span_no_DFR and beta_behav[, col]
## t = -0.46953, df = 148, p-value = 0.6394
## alternative hypothesis: true correlation is not equal to 0
## 95 percent confidence interval:
##  -0.1976069  0.1224517
## sample estimates:
##         cor 
## -0.03856671
## `geom_smooth()` using formula 'y ~ x'
## Warning: Removed 1 rows containing non-finite values (stat_smooth).
## Warning: Removed 1 rows containing missing values (geom_point).

## [1] "high_midOccip_cue"
## 
##  Pearson's product-moment correlation
## 
## data:  beta_behav$omnibus_span_no_DFR and beta_behav[, col]
## t = -0.91808, df = 150, p-value = 0.3601
## alternative hypothesis: true correlation is not equal to 0
## 95 percent confidence interval:
##  -0.23120015  0.08546697
## sample estimates:
##         cor 
## -0.07475082

Split by WMC

There are, however, no differences across groups in beta for either the high load trials or load effects.

midOccip_DFR_beta <- paired_freq_plot(split_betas_plot[["ERSPS_midOccip_DFR"]][["long"]], c("high","low", "load_effect"))

Oz_DFR_beta <- paired_freq_plot(split_betas_plot[["ERSPS_Oz_DFR"]][["long"]], c("high","low", "load_effect"))

midOccip_DFR_beta[[1]] + midOccip_DFR_beta[[2]]+
  plot_annotation(title="midOccip - beta during DFR")+
  plot_layout(guides="collect")

Oz_DFR_beta[[1]] + Oz_DFR_beta[[2]]+
  plot_annotation(title="Oz - beta during DFR")+
  plot_layout(guides="collect")

beta_cue_Oz_DFR_split <- split_into_groups(beta_cue_average_Oz, WM_groups)
beta_cue_midOccip_DFR_split <- split_into_groups(beta_cue_average_midOccip, WM_groups)

beta_delay_Oz_DFR_split <- split_into_groups(beta_delay_average_Oz, WM_groups)
beta_delay_midOccip_DFR_split <- split_into_groups(beta_delay_average_midOccip, WM_groups)

beta_probe_Oz_DFR_split <- split_into_groups(beta_probe_average_Oz, WM_groups)
beta_probe_midOccip_DFR_split <- split_into_groups(beta_probe_average_midOccip, WM_groups)

beta_cue_Oz_DFR_split_prepped <- prep_split_for_bar_plots(beta_cue_Oz_DFR_split)
beta_cue_midOccip_DFR_split_prepped <- prep_split_for_bar_plots(beta_cue_midOccip_DFR_split)

beta_delay_Oz_DFR_split_prepped <- prep_split_for_bar_plots(beta_delay_Oz_DFR_split)
beta_delay_midOccip_DFR_split_prepped <- prep_split_for_bar_plots(beta_delay_midOccip_DFR_split)

beta_probe_Oz_DFR_split_prepped <- prep_split_for_bar_plots(beta_probe_Oz_DFR_split)
beta_probe_midOccip_DFR_split_prepped <- prep_split_for_bar_plots(beta_probe_midOccip_DFR_split)
beta_cue_midOccip_DFR_anova <- merge(beta_cue_average_midOccip,WM_to_merge, by="PTID")
beta_delay_midOccip_DFR_anova <- merge(beta_delay_average_midOccip,WM_to_merge, by="PTID")
beta_probe_midOccip_DFR_anova <- merge(beta_probe_average_midOccip,WM_to_merge, by="PTID")

beta_cue_Oz_DFR_anova <- merge(beta_cue_average_Oz,WM_to_merge, by="PTID")
beta_delay_Oz_DFR_anova <- merge(beta_delay_average_Oz,WM_to_merge, by="PTID")
beta_probe_Oz_DFR_anova <- merge(beta_probe_average_Oz,WM_to_merge, by="PTID")
beta_cue_midOccip_DFR_split_prepped[["melt_data"]] %>% 
  filter(variable=="high_load") %>% 
  mutate(level = factor(level, levels =c("low","med","high"))) %>%
  ggplot()+
  geom_bar(aes(x=level,y=Means),stat="identity")+
  geom_errorbar(aes(x=level,ymin=Means-SE, ymax=Means+SE), width=0.2)+
  ggtitle("Cue")+ 
  xlab("WMC")+
  ylab("ERP amplitude LE")+
  theme_classic()+
  theme(aspect.ratio = 1) 

summary(rlm(omnibus_span_no_DFR ~ high_load, data = merge(beta_cue_midOccip_DFR_anova, constructs_fMRI)))
## 
## Call: rlm(formula = omnibus_span_no_DFR ~ high_load, data = merge(beta_cue_midOccip_DFR_anova, 
##     constructs_fMRI))
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -1.75389 -0.38833 -0.02816  0.34624  1.51144 
## 
## Coefficients:
##             Value   Std. Error t value
## (Intercept)  0.0306  0.0693     0.4411
## high_load   -0.0341  0.0279    -1.2236
## 
## Residual standard error: 0.5598 on 149 degrees of freedom
high_midOccip_cue_beta.aov <- aov(high_load ~ level, data = merge(beta_cue_midOccip_DFR_anova, constructs_fMRI))
summary(high_midOccip_cue_beta.aov)
##              Df Sum Sq Mean Sq F value Pr(>F)
## level         2    7.3   3.671   1.262  0.286
## Residuals   148  430.6   2.910
TukeyHSD(high_midOccip_cue_beta.aov)
##   Tukey multiple comparisons of means
##     95% family-wise confidence level
## 
## Fit: aov(formula = high_load ~ level, data = merge(beta_cue_midOccip_DFR_anova, constructs_fMRI))
## 
## $level
##                 diff        lwr       upr     p adj
## low-high  0.46767172 -0.3326950 1.2680385 0.3521931
## med-high  0.45617233 -0.3441944 1.2565391 0.3703126
## med-low  -0.01149939 -0.8274087 0.8044099 0.9993863
beta_cue_Oz_DFR_split_prepped[["melt_data"]] %>% 
  filter(variable=="load_effect") %>% 
  mutate(level = factor(level, levels =c("low","med","high"))) %>%
  ggplot()+
  geom_bar(aes(x=level,y=Means),stat="identity")+
  geom_errorbar(aes(x=level,ymin=Means-SE, ymax=Means+SE), width=0.2)+
  ggtitle("Cue")+ 
  xlab("WMC")+
  ylab("ERP amplitude LE")+
  theme_classic()+
  theme(aspect.ratio = 1) -> beta_cue_Oz_LE

beta_cue_midOccip_DFR_split_prepped[["melt_data"]] %>% 
  filter(variable=="load_effect") %>% 
  mutate(level = factor(level, levels =c("low","med","high"))) %>%
  ggplot()+
  geom_bar(aes(x=level,y=Means),stat="identity")+
  geom_errorbar(aes(x=level,ymin=Means-SE, ymax=Means+SE), width=0.2)+
  ggtitle("Cue")+ 
  xlab("WMC")+
  ylab("ERP amplitude LE")+
  theme_classic()+
  theme(aspect.ratio = 1) -> beta_cue_midOccip_LE

beta_delay_Oz_DFR_split_prepped[["melt_data"]] %>% 
  filter(variable=="load_effect") %>% 
  mutate(level = factor(level, levels =c("low","med","high"))) %>%
  ggplot()+
  geom_bar(aes(x=level,y=Means),stat="identity")+
  geom_errorbar(aes(x=level,ymin=Means-SE, ymax=Means+SE), width=0.2)+
  ggtitle("Delay")+ 
  xlab("WMC")+
  ylab("ERP amplitude LE")+
  theme_classic()+
  theme(aspect.ratio = 1) -> beta_delay_Oz_LE

beta_delay_midOccip_DFR_split_prepped[["melt_data"]] %>% 
  filter(variable=="load_effect") %>% 
  mutate(level = factor(level, levels =c("low","med","high"))) %>%
  ggplot()+
  geom_bar(aes(x=level,y=Means),stat="identity")+
  geom_errorbar(aes(x=level,ymin=Means-SE, ymax=Means+SE), width=0.2)+
  ggtitle("Delay")+ 
  xlab("WMC")+
  ylab("ERP amplitude LE")+
  theme_classic()+
  theme(aspect.ratio = 1) -> beta_delay_midOccip_LE

beta_probe_Oz_DFR_split_prepped[["melt_data"]] %>% 
  filter(variable=="load_effect") %>% 
  mutate(level = factor(level, levels =c("low","med","high"))) %>%
  ggplot()+
  geom_bar(aes(x=level,y=Means),stat="identity")+
  geom_errorbar(aes(x=level,ymin=Means-SE, ymax=Means+SE), width=0.2)+
  ggtitle("Probe")+ 
  xlab("WMC")+
  ylab("ERP amplitude LE")+
  theme_classic()+
  theme(aspect.ratio = 1) -> beta_probe_Oz_LE

beta_probe_midOccip_DFR_split_prepped[["melt_data"]] %>% 
  filter(variable=="load_effect") %>% 
  mutate(level = factor(level, levels =c("low","med","high"))) %>%
  ggplot()+
  geom_bar(aes(x=level,y=Means),stat="identity")+
  geom_errorbar(aes(x=level,ymin=Means-SE, ymax=Means+SE), width=0.2)+
  ggtitle("Probe")+ 
  xlab("WMC")+
  ylab("ERP amplitude LE")+
  theme_classic()+
  theme(aspect.ratio = 1) -> beta_probe_midOccip_LE

beta_cue_Oz_LE + beta_delay_Oz_LE + beta_probe_Oz_LE+
  plot_annotation(title="Oz electrode beta frequency Load Effect during DFR")

beta_cue_midOccip_LE + beta_delay_midOccip_LE + beta_probe_midOccip_LE+
  plot_annotation(title="midOccip cluster beta frequency Load Effect during DFR")

beta_cue_midOccip.aov <- aov(load_effect ~ level, data = beta_cue_midOccip_DFR_anova)
print("beta - cue midOccip")
## [1] "beta - cue midOccip"
print(summary(beta_cue_midOccip.aov))
##              Df Sum Sq Mean Sq F value Pr(>F)
## level         2   0.44  0.2184   0.215  0.807
## Residuals   148 150.35  1.0159
beta_delay_midOccip.aov <- aov(load_effect ~ level, data = beta_delay_midOccip_DFR_anova)
print("beta - delay midOccip")
## [1] "beta - delay midOccip"
print(summary(beta_delay_midOccip.aov))
##              Df Sum Sq Mean Sq F value Pr(>F)
## level         2   0.17  0.0848   0.069  0.933
## Residuals   148 182.06  1.2301
beta_probe_midOccip.aov <- aov(load_effect ~ level, data = beta_probe_midOccip_DFR_anova)
print("beta - probe midOccip")
## [1] "beta - probe midOccip"
print(summary(beta_probe_midOccip.aov))
##              Df Sum Sq Mean Sq F value Pr(>F)
## level         2   3.43   1.715    0.97  0.381
## Residuals   148 261.66   1.768
beta_cue_Oz.aov <- aov(load_effect ~ level, data = beta_cue_Oz_DFR_anova)
print("beta - cue Oz")
## [1] "beta - cue Oz"
print(summary(beta_cue_Oz.aov))
##              Df Sum Sq Mean Sq F value Pr(>F)
## level         2   1.56  0.7819   0.646  0.526
## Residuals   158 191.22  1.2103
beta_delay_Oz.aov <- aov(load_effect ~ level, data = beta_delay_Oz_DFR_anova)
print("beta - delay Oz")
## [1] "beta - delay Oz"
print(summary(beta_delay_Oz.aov))
##              Df Sum Sq Mean Sq F value Pr(>F)
## level         2   2.72   1.358   1.236  0.293
## Residuals   158 173.64   1.099

Theta

All Subjects

theta_plot_list[["ERSPS_Favg_DFR"]][["indiv_loads"]] + theta_plot_list[["ERSPS_Favg_DFR"]][["LE"]] +
  plot_annotation(title="Fz - theta during DFR")

theta_Favg_times <- time_sig_load_effects(theta[["ERSPS_Favg_DFR"]][["load_effect"]], ERSPS_times_DFR)
theta_cue_average_Favg <- select_period_average(theta[["ERSPS_Favg_DFR"]],1585.93750,1738.28125,ERSPS_times_DFR)

theta_delay_average_Favg <- select_period_average(theta[["ERSPS_Favg_DFR"]],2730.46875,2929.68750,ERSPS_times_DFR)

theta_probe_average_Favg <- select_period_average(theta[["ERSPS_Favg_DFR"]],5511.71875,7000.00000,ERSPS_times_DFR)
theta_data <- Reduce(function(x,y) merge(x,y, by="PTID"),
                         list(theta_cue_average_Favg[,c(1,4)], 
                              theta_delay_average_Favg[,c(1,4)],
                              theta_probe_average_Favg[,c(1,4)], 
                              theta_cue_average_Favg[,c(1,2)]))
colnames(theta_data) <- c("PTID", "cue_Favg", "delay_Favg", "probe_Favg","cue_Favg_high")

theta_behav <- merge(ERSP_behav_corr_data,theta_data, by = "PTID")

for (col in seq.int(5,8)){
  theta_behav[((theta_behav[,col] > mean(theta_behav[,col])+3*sd(theta_behav[,col])) | 
                     (theta_behav[,col] < mean(theta_behav[,col])-3*sd(theta_behav[,col]))), col] <- NA
}

for (col in seq.int(5,8)){
  print(ggplot(data = theta_behav, aes_string(x="omnibus_span_no_DFR", y = colnames(theta_behav)[col]))+
          geom_point()+
          stat_smooth(method="lm")+
          theme_classic()+
          theme(aspect.ratio=1))
  print(colnames(theta_behav)[col])
  print(cor.test(theta_behav$omnibus_span_no_DFR, theta_behav[,col]))
  
}
## `geom_smooth()` using formula 'y ~ x'
## Warning: Removed 3 rows containing non-finite values (stat_smooth).
## Warning: Removed 3 rows containing missing values (geom_point).

## [1] "cue_Favg"
## 
##  Pearson's product-moment correlation
## 
## data:  theta_behav$omnibus_span_no_DFR and theta_behav[, col]
## t = 1.3424, df = 158, p-value = 0.1814
## alternative hypothesis: true correlation is not equal to 0
## 95 percent confidence interval:
##  -0.04978708  0.25711435
## sample estimates:
##      cor 
## 0.106192
## `geom_smooth()` using formula 'y ~ x'
## Warning: Removed 2 rows containing non-finite values (stat_smooth).
## Warning: Removed 2 rows containing missing values (geom_point).

## [1] "delay_Favg"
## 
##  Pearson's product-moment correlation
## 
## data:  theta_behav$omnibus_span_no_DFR and theta_behav[, col]
## t = 0.84682, df = 159, p-value = 0.3984
## alternative hypothesis: true correlation is not equal to 0
## 95 percent confidence interval:
##  -0.08858691  0.21940696
## sample estimates:
##        cor 
## 0.06700607
## `geom_smooth()` using formula 'y ~ x'
## Warning: Removed 2 rows containing non-finite values (stat_smooth).

## Warning: Removed 2 rows containing missing values (geom_point).

## [1] "probe_Favg"
## 
##  Pearson's product-moment correlation
## 
## data:  theta_behav$omnibus_span_no_DFR and theta_behav[, col]
## t = -1.276, df = 159, p-value = 0.2038
## alternative hypothesis: true correlation is not equal to 0
## 95 percent confidence interval:
##  -0.25143521  0.05485332
## sample estimates:
##        cor 
## -0.1006757
## `geom_smooth()` using formula 'y ~ x'
## Warning: Removed 1 rows containing non-finite values (stat_smooth).
## Warning: Removed 1 rows containing missing values (geom_point).

## [1] "cue_Favg_high"
## 
##  Pearson's product-moment correlation
## 
## data:  theta_behav$omnibus_span_no_DFR and theta_behav[, col]
## t = -0.42389, df = 160, p-value = 0.6722
## alternative hypothesis: true correlation is not equal to 0
## 95 percent confidence interval:
##  -0.1867237  0.1213295
## sample estimates:
##         cor 
## -0.03349253

Split by WMC

Favg_DFR_theta <- paired_freq_plot(split_thetas_plot[["ERSPS_Fz_DFR"]][["long"]], c("high","low", "load_effect"))

Favg_DFR_theta[[1]] + Favg_DFR_theta[[2]]+
  plot_annotation(title="Favg - theta during DFR")+
  plot_layout(guides="collect")

theta_cue_Favg_DFR_split <- split_into_groups(theta_cue_average_Favg, WM_groups)

theta_delay_Favg_DFR_split <- split_into_groups(theta_delay_average_Favg, WM_groups)

theta_probe_Favg_DFR_split <- split_into_groups(theta_probe_average_Favg, WM_groups)

theta_cue_Favg_DFR_split_prepped <- prep_split_for_bar_plots(theta_cue_Favg_DFR_split)

theta_delay_Favg_DFR_split_prepped <- prep_split_for_bar_plots(theta_delay_Favg_DFR_split)

theta_probe_Favg_DFR_split_prepped <- prep_split_for_bar_plots(theta_probe_Favg_DFR_split)
theta_cue_Favg_DFR_anova <- merge(theta_cue_average_Favg,WM_to_merge, by="PTID")
theta_delay_Favg_DFR_anova <- merge(theta_delay_average_Favg,WM_to_merge, by="PTID")
theta_probe_Favg_DFR_anova <- merge(theta_probe_average_Favg,WM_to_merge, by="PTID")
theta_cue_Favg_DFR_split_prepped[["melt_data"]] %>% 
  filter(variable=="high_load") %>% 
  mutate(level = factor(level, levels =c("low","med","high"))) %>%
  ggplot()+
  geom_bar(aes(x=level,y=Means),stat="identity")+
  geom_errorbar(aes(x=level,ymin=Means-SE, ymax=Means+SE), width=0.2)+
  ggtitle("Cue")+ 
  xlab("WMC")+
  ylab("ERP amplitude LE")+
  theme_classic()+
  theme(aspect.ratio = 1) 

summary(rlm(omnibus_span_no_DFR ~ high_load, data = merge(theta_cue_Favg_DFR_anova, constructs_fMRI)))
## 
## Call: rlm(formula = omnibus_span_no_DFR ~ high_load, data = merge(theta_cue_Favg_DFR_anova, 
##     constructs_fMRI))
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -1.77741 -0.39358  0.00522  0.33419  1.53413 
## 
## Coefficients:
##             Value  Std. Error t value
## (Intercept) 0.1034 0.0557     1.8569 
## high_load   0.0245 0.0490     0.5011 
## 
## Residual standard error: 0.5079 on 159 degrees of freedom
high_Favg_cue_theta.aov <- aov(high_load ~ level, data = merge(theta_cue_Favg_DFR_anova, constructs_fMRI))
summary(high_Favg_cue_theta.aov)
##              Df Sum Sq Mean Sq F value Pr(>F)
## level         2   3.06  1.5280   1.669  0.192
## Residuals   158 144.64  0.9154
TukeyHSD(high_Favg_cue_theta.aov)
##   Tukey multiple comparisons of means
##     95% family-wise confidence level
## 
## Fit: aov(formula = high_load ~ level, data = merge(theta_cue_Favg_DFR_anova, constructs_fMRI))
## 
## $level
##                 diff        lwr       upr     p adj
## low-high -0.32641779 -0.7642769 0.1114414 0.1851913
## med-high -0.08250517 -0.5161764 0.3511660 0.8944189
## med-low   0.24391262 -0.1959124 0.6837377 0.3905531
theta_cue_Favg_DFR_split_prepped[["melt_data"]] %>% 
  filter(variable=="load_effect") %>% 
  mutate(level = factor(level, levels =c("low","med","high"))) %>%
  ggplot()+
  geom_bar(aes(x=level,y=Means),stat="identity")+
  geom_errorbar(aes(x=level,ymin=Means-SE, ymax=Means+SE), width=0.2)+
  ggtitle("Cue")+ 
  xlab("WMC")+
  ylab("ERP amplitude LE")+
  theme_classic()+
  theme(aspect.ratio = 1) -> theta_cue_Favg_LE

theta_delay_Favg_DFR_split_prepped[["melt_data"]] %>% 
  filter(variable=="load_effect") %>% 
  mutate(level = factor(level, levels =c("low","med","high"))) %>%
  ggplot()+
  geom_bar(aes(x=level,y=Means),stat="identity")+
  geom_errorbar(aes(x=level,ymin=Means-SE, ymax=Means+SE), width=0.2)+
  ggtitle("Delay")+ 
  xlab("WMC")+
  ylab("ERP amplitude LE")+
  theme_classic()+
  theme(aspect.ratio = 1) -> theta_delay_Favg_LE

theta_probe_Favg_DFR_split_prepped[["melt_data"]] %>% 
  filter(variable=="load_effect") %>% 
  mutate(level = factor(level, levels =c("low","med","high"))) %>%
  ggplot()+
  geom_bar(aes(x=level,y=Means),stat="identity")+
  geom_errorbar(aes(x=level,ymin=Means-SE, ymax=Means+SE), width=0.2)+
  ggtitle("Probe")+ 
  xlab("WMC")+
  ylab("ERP amplitude LE")+
  theme_classic()+
  theme(aspect.ratio = 1) -> theta_probe_Favg_LE

theta_cue_Favg_LE + theta_delay_Favg_LE + theta_probe_Favg_LE+
  plot_annotation(title="Favg cluster theta frequency Load Effect during DFR")

theta_cue_Favg.aov <- aov(load_effect ~ level, data = theta_cue_Favg_DFR_anova)
print("theta - cue Favg")
## [1] "theta - cue Favg"
print(summary(theta_cue_Favg.aov))
##              Df Sum Sq Mean Sq F value Pr(>F)
## level         2     99   49.32   1.441   0.24
## Residuals   158   5409   34.24
theta_delay_Favg.aov <- aov(load_effect ~ level, data = theta_delay_Favg_DFR_anova)
print("theta - delay Favg")
## [1] "theta - delay Favg"
print(summary(theta_delay_Favg.aov))
##              Df Sum Sq Mean Sq F value Pr(>F)
## level         2      5    2.47   0.053  0.949
## Residuals   158   7422   46.98
for (col in seq.int(5,8)){
  print(ggplot(data = theta_behav, aes_string(x="LE", y = colnames(theta_behav)[col]))+
          geom_point()+
          stat_smooth(method="lm")+
          theme_classic()+
          theme(aspect.ratio=1))
  print(colnames(theta_behav)[col])
  print(cor.test(theta_behav$LE, theta_behav[,col]))
  
}
## `geom_smooth()` using formula 'y ~ x'
## Warning: Removed 3 rows containing non-finite values (stat_smooth).
## Warning: Removed 3 rows containing missing values (geom_point).

## [1] "cue_Favg"
## 
##  Pearson's product-moment correlation
## 
## data:  theta_behav$LE and theta_behav[, col]
## t = 0.092011, df = 158, p-value = 0.9268
## alternative hypothesis: true correlation is not equal to 0
## 95 percent confidence interval:
##  -0.1480071  0.1622942
## sample estimates:
##         cor 
## 0.007319766
## `geom_smooth()` using formula 'y ~ x'
## Warning: Removed 2 rows containing non-finite values (stat_smooth).
## Warning: Removed 2 rows containing missing values (geom_point).

## [1] "delay_Favg"
## 
##  Pearson's product-moment correlation
## 
## data:  theta_behav$LE and theta_behav[, col]
## t = -0.10585, df = 159, p-value = 0.9158
## alternative hypothesis: true correlation is not equal to 0
## 95 percent confidence interval:
##  -0.1628573  0.1464711
## sample estimates:
##          cor 
## -0.008393911
## `geom_smooth()` using formula 'y ~ x'
## Warning: Removed 2 rows containing non-finite values (stat_smooth).

## Warning: Removed 2 rows containing missing values (geom_point).

## [1] "probe_Favg"
## 
##  Pearson's product-moment correlation
## 
## data:  theta_behav$LE and theta_behav[, col]
## t = -1.7809, df = 159, p-value = 0.07684
## alternative hypothesis: true correlation is not equal to 0
## 95 percent confidence interval:
##  -0.28828309  0.01515884
## sample estimates:
##        cor 
## -0.1398439
## `geom_smooth()` using formula 'y ~ x'
## Warning: Removed 1 rows containing non-finite values (stat_smooth).
## Warning: Removed 1 rows containing missing values (geom_point).

## [1] "cue_Favg_high"
## 
##  Pearson's product-moment correlation
## 
## data:  theta_behav$LE and theta_behav[, col]
## t = -1.3036, df = 160, p-value = 0.1943
## alternative hypothesis: true correlation is not equal to 0
## 95 percent confidence interval:
##  -0.25271303  0.05251334
## sample estimates:
##        cor 
## -0.1025122
summary(rlm(probe_Favg ~ LE, data = theta_behav))
## 
## Call: rlm(formula = probe_Favg ~ LE, data = theta_behav)
## Residuals:
##       Min        1Q    Median        3Q       Max 
## -34.55364  -4.15714   0.02535   3.82977  17.60469 
## 
## Coefficients:
##             Value   Std. Error t value
## (Intercept) -4.2197  0.5727    -7.3677
## LE          -2.9097  2.1611    -1.3464
## 
## Residual standard error: 5.79 on 159 degrees of freedom
##   (2 observations deleted due to missingness)
summary(rlm(cue_Favg_high ~ LE, data = theta_behav))
## 
## Call: rlm(formula = cue_Favg_high ~ LE, data = theta_behav)
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -2.76093 -0.53157  0.01827  0.61882  2.67969 
## 
## Coefficients:
##             Value   Std. Error t value
## (Intercept) -0.4703  0.0854    -5.5072
## LE          -0.5214  0.3223    -1.6175
## 
## Residual standard error: 0.8946 on 160 degrees of freedom
##   (1 observation deleted due to missingness)

Low Gamma

All Subjects

Significant load effects during delay and probe in the mid Occipital cluster and Oz electrode (low > high) and F avg during probe (low > high).

low_gamma_plot_list[["ERSPS_midOccip_DFR"]][["indiv_loads"]] + low_gamma_plot_list[["ERSPS_midOccip_DFR"]][["LE"]] +
  plot_annotation(title="midOccip - low_gamma during DFR")

low_gamma_plot_list[["ERSPS_Oz_DFR"]][["indiv_loads"]] + low_gamma_plot_list[["ERSPS_Oz_DFR"]][["LE"]] +
  plot_annotation(title="Oz - low_gamma during DFR")

low_gamma_mid_occip_times <- time_sig_load_effects(low_gamma[["ERSPS_midOccip_DFR"]][["load_effect"]], ERSPS_times_DFR)
low_gamma_Oz_times <- time_sig_load_effects(low_gamma[["ERSPS_Oz_DFR"]][["load_effect"]], ERSPS_times_DFR)
low_gamma_cue_average_midOccip <- select_period_average(low_gamma[["ERSPS_midOccip_DFR"]],496.09375,742.18750,ERSPS_times_DFR)
low_gamma_cue_average_Oz <- select_period_average(low_gamma[["ERSPS_Oz_DFR"]],1437.50000,2433.59375,ERSPS_times_DFR)

low_gamma_delay_average_midOccip <- select_period_average(low_gamma[["ERSPS_midOccip_DFR"]],2582.03125,3078.12500,ERSPS_times_DFR)
low_gamma_delay_average_Oz <- select_period_average(low_gamma[["ERSPS_Oz_DFR"]],2878.90625,3175.78125,ERSPS_times_DFR)

low_gamma_probe_average_midOccip <- select_period_average(low_gamma[["ERSPS_midOccip_DFR"]],5609.37500,6800.78125,ERSPS_times_DFR)
low_gamma_probe_average_Oz <- select_period_average(low_gamma[["ERSPS_Oz_DFR"]],5660.15625,6652.34375,ERSPS_times_DFR)
t.test(low_gamma_cue_average_midOccip$load_effect,mu=0)
## 
##  One Sample t-test
## 
## data:  low_gamma_cue_average_midOccip$load_effect
## t = 3.0978, df = 177, p-value = 0.002268
## alternative hypothesis: true mean is not equal to 0
## 95 percent confidence interval:
##  0.0411968 0.1858122
## sample estimates:
## mean of x 
## 0.1135045
t.test(low_gamma_cue_average_Oz$load_effect,mu=0)
## 
##  One Sample t-test
## 
## data:  low_gamma_cue_average_Oz$load_effect
## t = -2.8706, df = 189, p-value = 0.004564
## alternative hypothesis: true mean is not equal to 0
## 95 percent confidence interval:
##  -0.37793883 -0.07007582
## sample estimates:
##  mean of x 
## -0.2240073
t.test(low_gamma_delay_average_midOccip$load_effect,mu=0)
## 
##  One Sample t-test
## 
## data:  low_gamma_delay_average_midOccip$load_effect
## t = -3.1938, df = 177, p-value = 0.001662
## alternative hypothesis: true mean is not equal to 0
## 95 percent confidence interval:
##  -0.31132319 -0.07352651
## sample estimates:
##  mean of x 
## -0.1924248
t.test(low_gamma_delay_average_Oz$load_effect,mu=0)
## 
##  One Sample t-test
## 
## data:  low_gamma_delay_average_Oz$load_effect
## t = -3.07, df = 189, p-value = 0.002456
## alternative hypothesis: true mean is not equal to 0
## 95 percent confidence interval:
##  -0.4840476 -0.1053392
## sample estimates:
##  mean of x 
## -0.2946934
t.test(low_gamma_probe_average_midOccip$load_effect,mu=0)
## 
##  One Sample t-test
## 
## data:  low_gamma_probe_average_midOccip$load_effect
## t = -4.5266, df = 177, p-value = 1.097e-05
## alternative hypothesis: true mean is not equal to 0
## 95 percent confidence interval:
##  -0.6269540 -0.2462602
## sample estimates:
##  mean of x 
## -0.4366071
t.test(low_gamma_probe_average_Oz$load_effect,mu=0)
## 
##  One Sample t-test
## 
## data:  low_gamma_probe_average_Oz$load_effect
## t = -4.6853, df = 189, p-value = 5.334e-06
## alternative hypothesis: true mean is not equal to 0
## 95 percent confidence interval:
##  -0.8101677 -0.3300941
## sample estimates:
##  mean of x 
## -0.5701309
low_gamma_data <- Reduce(function(x,y) merge(x,y, by="PTID"),
                         list(low_gamma_cue_average_midOccip[,c(1,4)], low_gamma_cue_average_Oz[,c(1,4)],
                              low_gamma_delay_average_midOccip[,c(1,4)],low_gamma_delay_average_Oz[,c(1,4)],
                              low_gamma_probe_average_midOccip[,c(1,4)],
                              low_gamma_probe_average_Oz[,c(1,4)], 
                              low_gamma_probe_average_midOccip[,c(1,2)],
                              low_gamma_probe_average_Oz[,c(1,2)]))
## Warning in merge.data.frame(x, y, by = "PTID"): column names 'load_effect.x',
## 'load_effect.y' are duplicated in the result

## Warning in merge.data.frame(x, y, by = "PTID"): column names 'load_effect.x',
## 'load_effect.y' are duplicated in the result
## Warning in merge.data.frame(x, y, by = "PTID"): column names 'load_effect.x',
## 'load_effect.y', 'load_effect.x', 'load_effect.y' are duplicated in the result

## Warning in merge.data.frame(x, y, by = "PTID"): column names 'load_effect.x',
## 'load_effect.y', 'load_effect.x', 'load_effect.y' are duplicated in the result

## Warning in merge.data.frame(x, y, by = "PTID"): column names 'load_effect.x',
## 'load_effect.y', 'load_effect.x', 'load_effect.y' are duplicated in the result
colnames(low_gamma_data) <- c("PTID", "cue_midOccip", "cue_Oz", "delay_midOccip","delay_Oz", "probe_midOccip", "probe_Oz", "cue_midOccip_high", "cue_Oz_high")

low_gamma_behav <- merge(ERSP_behav_corr_data,low_gamma_data, by = "PTID")

for (col in seq.int(5,11)){
  low_gamma_behav[((low_gamma_behav[,col] > mean(low_gamma_behav[,col])+3*sd(low_gamma_behav[,col])) | 
                     (low_gamma_behav[,col] < mean(low_gamma_behav[,col])-3*sd(low_gamma_behav[,col]))), col] <- NA
}

for (col in seq.int(5,11)){
  print(ggplot(data = low_gamma_behav, aes_string(x="omnibus_span_no_DFR", y = colnames(low_gamma_behav)[col]))+
          geom_point()+
          stat_smooth(method="lm")+
          theme_classic()+
          theme(aspect.ratio=1))
  print(colnames(low_gamma_behav)[col])
  print(cor.test(low_gamma_behav$omnibus_span_no_DFR, low_gamma_behav[,col]))
  
}
## `geom_smooth()` using formula 'y ~ x'
## Warning: Removed 1 rows containing non-finite values (stat_smooth).
## Warning: Removed 1 rows containing missing values (geom_point).

## [1] "cue_midOccip"
## 
##  Pearson's product-moment correlation
## 
## data:  low_gamma_behav$omnibus_span_no_DFR and low_gamma_behav[, col]
## t = 0.81173, df = 150, p-value = 0.4182
## alternative hypothesis: true correlation is not equal to 0
## 95 percent confidence interval:
##  -0.09405886  0.22298517
## sample estimates:
##        cor 
## 0.06613212
## `geom_smooth()` using formula 'y ~ x'
## Warning: Removed 2 rows containing non-finite values (stat_smooth).
## Warning: Removed 2 rows containing missing values (geom_point).

## [1] "cue_Oz"
## 
##  Pearson's product-moment correlation
## 
## data:  low_gamma_behav$omnibus_span_no_DFR and low_gamma_behav[, col]
## t = -0.6178, df = 149, p-value = 0.5376
## alternative hypothesis: true correlation is not equal to 0
## 95 percent confidence interval:
##  -0.2085920  0.1100694
## sample estimates:
##         cor 
## -0.05054771
## `geom_smooth()` using formula 'y ~ x'
## Warning: Removed 2 rows containing non-finite values (stat_smooth).

## Warning: Removed 2 rows containing missing values (geom_point).

## [1] "delay_midOccip"
## 
##  Pearson's product-moment correlation
## 
## data:  low_gamma_behav$omnibus_span_no_DFR and low_gamma_behav[, col]
## t = -0.3149, df = 149, p-value = 0.7533
## alternative hypothesis: true correlation is not equal to 0
## 95 percent confidence interval:
##  -0.1847563  0.1344936
## sample estimates:
##         cor 
## -0.02578884
## `geom_smooth()` using formula 'y ~ x'
## Warning: Removed 2 rows containing non-finite values (stat_smooth).

## Warning: Removed 2 rows containing missing values (geom_point).

## [1] "delay_Oz"
## 
##  Pearson's product-moment correlation
## 
## data:  low_gamma_behav$omnibus_span_no_DFR and low_gamma_behav[, col]
## t = 1.028, df = 149, p-value = 0.3056
## alternative hypothesis: true correlation is not equal to 0
## 95 percent confidence interval:
##  -0.07683779  0.24042633
## sample estimates:
##        cor 
## 0.08392066
## `geom_smooth()` using formula 'y ~ x'
## Warning: Removed 1 rows containing non-finite values (stat_smooth).
## Warning: Removed 1 rows containing missing values (geom_point).

## [1] "probe_midOccip"
## 
##  Pearson's product-moment correlation
## 
## data:  low_gamma_behav$omnibus_span_no_DFR and low_gamma_behav[, col]
## t = 0.70054, df = 150, p-value = 0.4847
## alternative hypothesis: true correlation is not equal to 0
## 95 percent confidence interval:
##  -0.1030322  0.2143571
## sample estimates:
##        cor 
## 0.05710515
## `geom_smooth()` using formula 'y ~ x'
## Warning: Removed 2 rows containing non-finite values (stat_smooth).
## Warning: Removed 2 rows containing missing values (geom_point).

## [1] "probe_Oz"
## 
##  Pearson's product-moment correlation
## 
## data:  low_gamma_behav$omnibus_span_no_DFR and low_gamma_behav[, col]
## t = 0.22271, df = 149, p-value = 0.8241
## alternative hypothesis: true correlation is not equal to 0
## 95 percent confidence interval:
##  -0.1418998  0.1774536
## sample estimates:
##        cor 
## 0.01824215
## `geom_smooth()` using formula 'y ~ x'
## Warning: Removed 3 rows containing non-finite values (stat_smooth).
## Warning: Removed 3 rows containing missing values (geom_point).

## [1] "cue_midOccip_high"
## 
##  Pearson's product-moment correlation
## 
## data:  low_gamma_behav$omnibus_span_no_DFR and low_gamma_behav[, col]
## t = -1.3206, df = 148, p-value = 0.1887
## alternative hypothesis: true correlation is not equal to 0
## 95 percent confidence interval:
##  -0.26362441  0.05326022
## sample estimates:
##        cor 
## -0.1079225

Split by WMC

In the low gamma band, the only load effect that shows any difference is Oz during cue, with a trend for an inverted U shape relationship.

In the raw power, however, we do see differences between groups in the cue and delay periods in the mid occipcital cluster and Oz electrodes. In the cue and delay for mid occipital and delay for Oz, we see a significant low > high difference, and in cue period for the mid occipital and cue and delay for Oz, we see a med > high difference.

midOccip_DFR_low_gamma <- paired_freq_plot(split_low_gammas_plot[["ERSPS_midOccip_DFR"]][["long"]], c("high","low", "load_effect"))
Oz_DFR_low_gamma <- paired_freq_plot(split_low_gammas_plot[["ERSPS_Oz_DFR"]][["long"]], c("high","low", "load_effect"))

midOccip_DFR_low_gamma[[1]] + midOccip_DFR_low_gamma[[2]]+
  plot_annotation(title="midOccip - low_gamma during DFR")+
  plot_layout(guides="collect")

Oz_DFR_low_gamma[[1]] + Oz_DFR_low_gamma[[2]]+
  plot_annotation(title="Oz - low_gamma during DFR")+
  plot_layout(guides="collect")

low_gamma_cue_Oz_DFR_split <- split_into_groups(low_gamma_cue_average_Oz, WM_groups)
low_gamma_cue_midOccip_DFR_split <- split_into_groups(low_gamma_cue_average_midOccip, WM_groups)

low_gamma_delay_Oz_DFR_split <- split_into_groups(low_gamma_delay_average_Oz, WM_groups)
low_gamma_delay_midOccip_DFR_split <- split_into_groups(low_gamma_delay_average_midOccip, WM_groups)

low_gamma_probe_Oz_DFR_split <- split_into_groups(low_gamma_probe_average_Oz, WM_groups)
low_gamma_probe_midOccip_DFR_split <- split_into_groups(low_gamma_probe_average_midOccip, WM_groups)

low_gamma_cue_Oz_DFR_split_prepped <- prep_split_for_bar_plots(low_gamma_cue_Oz_DFR_split)
low_gamma_cue_midOccip_DFR_split_prepped <- prep_split_for_bar_plots(low_gamma_cue_midOccip_DFR_split)

low_gamma_delay_Oz_DFR_split_prepped <- prep_split_for_bar_plots(low_gamma_delay_Oz_DFR_split)
low_gamma_delay_midOccip_DFR_split_prepped <- prep_split_for_bar_plots(low_gamma_delay_midOccip_DFR_split)

low_gamma_probe_Oz_DFR_split_prepped <- prep_split_for_bar_plots(low_gamma_probe_Oz_DFR_split)
low_gamma_probe_midOccip_DFR_split_prepped <- prep_split_for_bar_plots(low_gamma_probe_midOccip_DFR_split)
low_gamma_cue_midOccip_DFR_anova <- merge(low_gamma_cue_average_midOccip,WM_to_merge, by="PTID")
low_gamma_delay_midOccip_DFR_anova <- merge(low_gamma_delay_average_midOccip,WM_to_merge, by="PTID")
low_gamma_probe_midOccip_DFR_anova <- merge(low_gamma_probe_average_midOccip,WM_to_merge, by="PTID")

low_gamma_cue_Oz_DFR_anova <- merge(low_gamma_cue_average_Oz,WM_to_merge, by="PTID")
low_gamma_delay_Oz_DFR_anova <- merge(low_gamma_delay_average_Oz,WM_to_merge, by="PTID")
low_gamma_probe_Oz_DFR_anova <- merge(low_gamma_probe_average_Oz,WM_to_merge, by="PTID")
low_gamma_cue_midOccip_DFR_split_prepped[["melt_data"]] %>% 
  filter(variable=="high_load") %>% 
  mutate(level = factor(level, levels =c("low","med","high"))) %>%
  ggplot()+
  geom_bar(aes(x=level,y=Means),stat="identity")+
  geom_errorbar(aes(x=level,ymin=Means-SE, ymax=Means+SE), width=0.2)+
  ggtitle("Cue")+ 
  xlab("WMC")+
  ylab("ERP amplitude LE")+
  theme_classic()+
  theme(aspect.ratio = 1) 

summary(rlm(omnibus_span_no_DFR ~ high_load, data = merge(low_gamma_cue_midOccip_DFR_anova, constructs_fMRI)))
## 
## Call: rlm(formula = omnibus_span_no_DFR ~ high_load, data = merge(low_gamma_cue_midOccip_DFR_anova, 
##     constructs_fMRI))
## Residuals:
##       Min        1Q    Median        3Q       Max 
## -1.737992 -0.374052  0.004199  0.373007  1.476973 
## 
## Coefficients:
##             Value   Std. Error t value
## (Intercept)  0.0667  0.0513     1.3000
## high_load   -0.1350  0.0881    -1.5330
## 
## Residual standard error: 0.5594 on 149 degrees of freedom
high_midOccip_cue_low_gamma.aov <- aov(high_load ~ level, data = merge(low_gamma_cue_midOccip_DFR_anova, constructs_fMRI))
summary(high_midOccip_cue_low_gamma.aov)
##              Df Sum Sq Mean Sq F value Pr(>F)
## level         2   1.11  0.5567   1.865  0.159
## Residuals   148  44.18  0.2985
TukeyHSD(high_midOccip_cue_low_gamma.aov)
##   Tukey multiple comparisons of means
##     95% family-wise confidence level
## 
## Fit: aov(formula = high_load ~ level, data = merge(low_gamma_cue_midOccip_DFR_anova, constructs_fMRI))
## 
## $level
##                diff         lwr       upr     p adj
## low-high 0.16630460 -0.09005812 0.4226673 0.2771990
## med-high 0.19108201 -0.06528070 0.4474447 0.1851246
## med-low  0.02477742 -0.23656368 0.2861185 0.9726124
low_gamma_cue_Oz_DFR_split_prepped[["melt_data"]] %>% 
  filter(variable=="high_load") %>% 
  mutate(level = factor(level, levels =c("low","med","high"))) %>%
  ggplot()+
  geom_bar(aes(x=level,y=Means),stat="identity")+
  geom_errorbar(aes(x=level,ymin=Means-SE, ymax=Means+SE), width=0.2)+
  ggtitle("Cue")+ 
  xlab("WMC")+
  ylab("ERP amplitude LE")+
  theme_classic()+
  theme(aspect.ratio = 1) 

summary(rlm(omnibus_span_no_DFR ~ high_load, data = merge(low_gamma_cue_Oz_DFR_anova, constructs_fMRI)))
## 
## Call: rlm(formula = omnibus_span_no_DFR ~ high_load, data = merge(low_gamma_cue_Oz_DFR_anova, 
##     constructs_fMRI))
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -1.63210 -0.39945  0.01806  0.37124  1.53542 
## 
## Coefficients:
##             Value   Std. Error t value
## (Intercept)  0.0461  0.0507     0.9093
## high_load   -0.0658  0.0324    -2.0314
## 
## Residual standard error: 0.5876 on 159 degrees of freedom
high_Oz_cue_low_gamma.aov <- aov(high_load ~ level, data = merge(low_gamma_cue_Oz_DFR_anova, constructs_fMRI))
summary(high_Oz_cue_low_gamma.aov)
##              Df Sum Sq Mean Sq F value Pr(>F)
## level         2    8.8   4.392   2.104  0.125
## Residuals   158  329.8   2.088
TukeyHSD(high_Oz_cue_low_gamma.aov)
##   Tukey multiple comparisons of means
##     95% family-wise confidence level
## 
## Fit: aov(formula = high_load ~ level, data = merge(low_gamma_cue_Oz_DFR_anova, constructs_fMRI))
## 
## $level
##               diff        lwr       upr     p adj
## low-high 0.4225172 -0.2386968 1.0837312 0.2880905
## med-high 0.5397408 -0.1151489 1.1946306 0.1282630
## med-low  0.1172236 -0.5469590 0.7814063 0.9084234
low_gamma_cue_Oz_DFR_split_prepped[["melt_data"]] %>% 
  filter(variable=="load_effect") %>% 
  mutate(level = factor(level, levels =c("low","med","high"))) %>%
  ggplot()+
  geom_bar(aes(x=level,y=Means),stat="identity")+
  geom_errorbar(aes(x=level,ymin=Means-SE, ymax=Means+SE), width=0.2)+
  ggtitle("Cue")+ 
  xlab("WMC")+
  ylab("ERP amplitude LE")+
  theme_classic()+
  theme(aspect.ratio = 1) -> low_gamma_cue_Oz_LE

low_gamma_cue_midOccip_DFR_split_prepped[["melt_data"]] %>% 
  filter(variable=="load_effect") %>% 
  mutate(level = factor(level, levels =c("low","med","high"))) %>%
  ggplot()+
  geom_bar(aes(x=level,y=Means),stat="identity")+
  geom_errorbar(aes(x=level,ymin=Means-SE, ymax=Means+SE), width=0.2)+
  ggtitle("Cue")+ 
  xlab("WMC")+
  ylab("ERP amplitude LE")+
  theme_classic()+
  theme(aspect.ratio = 1) -> low_gamma_cue_midOccip_LE

low_gamma_delay_Oz_DFR_split_prepped[["melt_data"]] %>% 
  filter(variable=="load_effect") %>% 
  mutate(level = factor(level, levels =c("low","med","high"))) %>%
  ggplot()+
  geom_bar(aes(x=level,y=Means),stat="identity")+
  geom_errorbar(aes(x=level,ymin=Means-SE, ymax=Means+SE), width=0.2)+
  ggtitle("Delay")+ 
  xlab("WMC")+
  ylab("ERP amplitude LE")+
  theme_classic()+
  theme(aspect.ratio = 1) -> low_gamma_delay_Oz_LE

low_gamma_delay_midOccip_DFR_split_prepped[["melt_data"]] %>% 
  filter(variable=="load_effect") %>% 
  mutate(level = factor(level, levels =c("low","med","high"))) %>%
  ggplot()+
  geom_bar(aes(x=level,y=Means),stat="identity")+
  geom_errorbar(aes(x=level,ymin=Means-SE, ymax=Means+SE), width=0.2)+
  ggtitle("Delay")+ 
  xlab("WMC")+
  ylab("ERP amplitude LE")+
  theme_classic()+
  theme(aspect.ratio = 1) -> low_gamma_delay_midOccip_LE

low_gamma_probe_Oz_DFR_split_prepped[["melt_data"]] %>% 
  filter(variable=="load_effect") %>% 
  mutate(level = factor(level, levels =c("low","med","high"))) %>%
  ggplot()+
  geom_bar(aes(x=level,y=Means),stat="identity")+
  geom_errorbar(aes(x=level,ymin=Means-SE, ymax=Means+SE), width=0.2)+
  ggtitle("Probe")+ 
  xlab("WMC")+
  ylab("ERP amplitude LE")+
  theme_classic()+
  theme(aspect.ratio = 1) -> low_gamma_probe_Oz_LE

low_gamma_probe_midOccip_DFR_split_prepped[["melt_data"]] %>% 
  filter(variable=="load_effect") %>% 
  mutate(level = factor(level, levels =c("low","med","high"))) %>%
  ggplot()+
  geom_bar(aes(x=level,y=Means),stat="identity")+
  geom_errorbar(aes(x=level,ymin=Means-SE, ymax=Means+SE), width=0.2)+
  ggtitle("Probe")+ 
  xlab("WMC")+
  ylab("ERP amplitude LE")+
  theme_classic()+
  theme(aspect.ratio = 1) -> low_gamma_probe_midOccip_LE

low_gamma_cue_Oz_LE + low_gamma_delay_Oz_LE + low_gamma_probe_Oz_LE+
  plot_annotation(title="Oz electrode low_gamma frequency Load Effect during DFR")

low_gamma_cue_midOccip_LE + low_gamma_delay_midOccip_LE + low_gamma_probe_midOccip_LE+
  plot_annotation(title="midOccip cluster low_gamma frequency Load Effect during DFR")

low_gamma_cue_midOccip.aov <- aov(load_effect ~ level, data = low_gamma_cue_midOccip_DFR_anova)
print("low_gamma - cue midOccip")
## [1] "low_gamma - cue midOccip"
print(summary(low_gamma_cue_midOccip.aov))
##              Df Sum Sq Mean Sq F value Pr(>F)
## level         2   0.01 0.00417   0.018  0.982
## Residuals   148  33.37 0.22550
low_gamma_delay_midOccip.aov <- aov(load_effect ~ level, data = low_gamma_delay_midOccip_DFR_anova)
print("low_gamma - delay midOccip")
## [1] "low_gamma - delay midOccip"
print(summary(low_gamma_delay_midOccip.aov))
##              Df Sum Sq Mean Sq F value Pr(>F)
## level         2   0.21  0.1033   0.152  0.859
## Residuals   148 100.57  0.6795
low_gamma_cue_Oz.aov <- aov(load_effect ~ level, data = low_gamma_cue_Oz_DFR_anova)
print("low_gamma - cue Oz")
## [1] "low_gamma - cue Oz"
print(summary(low_gamma_cue_Oz.aov))
##              Df Sum Sq Mean Sq F value Pr(>F)
## level         2   0.66  0.3303   0.294  0.746
## Residuals   158 177.67  1.1245
low_gamma_delay_Oz.aov <- aov(load_effect ~ level, data = low_gamma_delay_Oz_DFR_anova)
print("low_gamma - delay Oz")
## [1] "low_gamma - delay Oz"
print(summary(low_gamma_delay_Oz.aov))
##              Df Sum Sq Mean Sq F value Pr(>F)
## level         2    0.1  0.0494   0.027  0.973
## Residuals   158  289.7  1.8335

CDA

CDA <- data.frame(read.csv("data/EEG/LCD/ERPS_CDA.txt"))
CDA_fMRI <- CDA[CDA$subID %in% constructs_fMRI$PTID,]
CDA_fMRI[is.nan(CDA_fMRI[,2]),2:11] <- NA
colnames(CDA_fMRI)[1] <- "PTID"
CDA_fMRI$CDA_3_1 <- CDA_fMRI$LCD_CDA_3dots - CDA_fMRI$LCD_CDA_1dots
CDA_fMRI$CDA_5_1 <- CDA_fMRI$LCD_CDA_5dots - CDA_fMRI$LCD_CDA_1dots
CDA_fMRI$CDA_5_3 <- CDA_fMRI$LCD_CDA_5dots - CDA_fMRI$LCD_CDA_3dots

Raw Data

First, let’s take a look at the raw data, just for sanity’s sake.

CDA_fMRI %>% 
  dplyr::select(c("LCD_CDA_1dots", "LCD_CDA_3dots", "LCD_CDA_5dots")) %>% 
  melt() %>% 
  ggplot(aes(x=variable,y=value))+
  geom_jitter()+
  stat_summary(fun.data=mean_sdl, geom="pointrange", color="red")+
  xlab("Level")+
  ylab("CDA")
## No id variables; using all as measure variables
## Warning: Removed 24 rows containing non-finite values (stat_summary).
## Warning: Removed 24 rows containing missing values (geom_point).

CDA_fMRI %>% 
  dplyr::select(c("CDA_3_1", "CDA_5_1", "CDA_5_3")) %>% 
  melt() %>% 
  ggplot(aes(x=variable,y=value))+
  geom_jitter()+
  stat_summary(fun.data=mean_sdl, geom="pointrange", color="red")+
  xlab("Level differences")+
  ylab("CDA Load Effects")
## No id variables; using all as measure variables
## Warning: Removed 24 rows containing non-finite values (stat_summary).

## Warning: Removed 24 rows containing missing values (geom_point).

Relationship of Raw Data with Span

Other studies have shown a relationship between the CDA and capacity as measured by LCD K. Our data, only showed a correlation between the CDA in the low load condition (1 dot) and the LCD K max, with no correlation between omnibus span or DFR load effect.

data_to_plot <- data.frame(CDA_fMRI, p200_delay_DFR,p200_indiv_ROI_DFR_delay, omnibus_span = constructs_fMRI$omnibus_span_no_DFR)
data_to_plot <- merge(data_to_plot,p200_cog)

(ggplot(data_to_plot,aes(x=DFR_Load3_Load1, y=LCD_CDA_5dots))+
    geom_point()+
    stat_smooth(method="lm")+
    ylim(c(-5,2.5))+
    theme_classic())+(ggplot(data_to_plot,aes(x=DFR_Load3_Load1, y=LCD_CDA_3dots))+
                        geom_point()+
                        stat_smooth(method="lm")+
                        ylim(c(-5,2.5))+
                        theme_classic())+(ggplot(data_to_plot,aes(x=DFR_Load3_Load1, y=LCD_CDA_1dots))+
                                            geom_point()+
                                            stat_smooth(method="lm")+
                                            ylim(c(-5,2.5))+
                                            theme_classic()+
                                            theme(aspect.ratio=1))
## `geom_smooth()` using formula 'y ~ x'
## Warning: Removed 8 rows containing non-finite values (stat_smooth).
## Warning: Removed 8 rows containing missing values (geom_point).
## `geom_smooth()` using formula 'y ~ x'
## Warning: Removed 8 rows containing non-finite values (stat_smooth).

## Warning: Removed 8 rows containing missing values (geom_point).
## `geom_smooth()` using formula 'y ~ x'
## Warning: Removed 8 rows containing non-finite values (stat_smooth).

## Warning: Removed 8 rows containing missing values (geom_point).

# cor.test(data_to_plot$LCD_CDA_5dots, data_to_plot$DFR_Load3_Load1)
summary(rlm(DFR_Load3_Load1 ~ LCD_CDA_5dots, data = data_to_plot))
## 
## Call: rlm(formula = DFR_Load3_Load1 ~ LCD_CDA_5dots, data = data_to_plot)
## Residuals:
##       Min        1Q    Median        3Q       Max 
## -0.586962 -0.123073 -0.006579  0.134029  1.033181 
## 
## Coefficients:
##               Value  Std. Error t value
## (Intercept)   0.1355 0.0194     6.9720 
## LCD_CDA_5dots 0.0090 0.0270     0.3315 
## 
## Residual standard error: 0.1909 on 160 degrees of freedom
##   (8 observations deleted due to missingness)
# cor.test(data_to_plot$LCD_CDA_3dots, data_to_plot$DFR_Load3_Load1)
summary(rlm(DFR_Load3_Load1 ~ LCD_CDA_3dots, data = data_to_plot))
## 
## Call: rlm(formula = DFR_Load3_Load1 ~ LCD_CDA_3dots, data = data_to_plot)
## Residuals:
##       Min        1Q    Median        3Q       Max 
## -0.598843 -0.127401 -0.005685  0.126950  0.976382 
## 
## Coefficients:
##               Value   Std. Error t value
## (Intercept)    0.1107  0.0195     5.6845
## LCD_CDA_3dots -0.0454  0.0242    -1.8798
## 
## Residual standard error: 0.1897 on 160 degrees of freedom
##   (8 observations deleted due to missingness)
# cor.test(data_to_plot$LCD_CDA_1dots, data_to_plot$DFR_Load3_Load1)
summary(rlm(DFR_Load3_Load1 ~ LCD_CDA_1dots, data = data_to_plot))
## 
## Call: rlm(formula = DFR_Load3_Load1 ~ LCD_CDA_1dots, data = data_to_plot)
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -0.57742 -0.12484 -0.01607  0.14042  1.01723 
## 
## Coefficients:
##               Value  Std. Error t value
## (Intercept)   0.1360 0.0167     8.1327 
## LCD_CDA_1dots 0.0239 0.0297     0.8067 
## 
## Residual standard error: 0.1981 on 160 degrees of freedom
##   (8 observations deleted due to missingness)
(ggplot(data_to_plot,aes(x=DFR_L_IPS, y=LCD_CDA_5dots))+
  geom_point()+
  stat_smooth(method="lm")+
  ylim(c(-5,2.5))+
  theme_classic())+(ggplot(data_to_plot,aes(x=DFR_L_IPS, y=LCD_CDA_3dots))+
                      geom_point()+
                      stat_smooth(method="lm")+
                      ylim(c(-5,2.5))+
                      theme_classic())+(ggplot(data_to_plot,aes(x=DFR_L_IPS, y=LCD_CDA_1dots))+
                                          geom_point()+
                                          stat_smooth(method="lm")+
                                          ylim(c(-5,2.5))+
                                          theme_classic()+
                                          theme(aspect.ratio=1))
## `geom_smooth()` using formula 'y ~ x'
## Warning: Removed 8 rows containing non-finite values (stat_smooth).

## Warning: Removed 8 rows containing missing values (geom_point).
## `geom_smooth()` using formula 'y ~ x'
## Warning: Removed 8 rows containing non-finite values (stat_smooth).

## Warning: Removed 8 rows containing missing values (geom_point).
## `geom_smooth()` using formula 'y ~ x'
## Warning: Removed 8 rows containing non-finite values (stat_smooth).

## Warning: Removed 8 rows containing missing values (geom_point).

# cor.test(data_to_plot$LCD_CDA_5dots, data_to_plot$DFR_L_IPS)
summary(rlm(DFR_L_IPS ~ LCD_CDA_5dots, data = data_to_plot))
## 
## Call: rlm(formula = DFR_L_IPS ~ LCD_CDA_5dots, data = data_to_plot)
## Residuals:
##       Min        1Q    Median        3Q       Max 
## -0.764821 -0.131259  0.007343  0.147228  0.879350 
## 
## Coefficients:
##               Value   Std. Error t value
## (Intercept)    0.1324  0.0209     6.3299
## LCD_CDA_5dots -0.0144  0.0291    -0.4944
## 
## Residual standard error: 0.2019 on 160 degrees of freedom
##   (8 observations deleted due to missingness)
# cor.test(data_to_plot$LCD_CDA_3dots, data_to_plot$DFR_L_IPS)
summary(rlm(DFR_L_IPS ~ LCD_CDA_3dots, data = data_to_plot))
## 
## Call: rlm(formula = DFR_L_IPS ~ LCD_CDA_3dots, data = data_to_plot)
## Residuals:
##        Min         1Q     Median         3Q        Max 
## -0.7443854 -0.1313361 -0.0003169  0.1319243  0.8484531 
## 
## Coefficients:
##               Value   Std. Error t value
## (Intercept)    0.1169  0.0211     5.5518
## LCD_CDA_3dots -0.0421  0.0261    -1.6135
## 
## Residual standard error: 0.1959 on 160 degrees of freedom
##   (8 observations deleted due to missingness)
# cor.test(data_to_plot$LCD_CDA_1dots, data_to_plot$DFR_L_IPS)
summary(rlm(DFR_L_IPS ~ LCD_CDA_1dots, data = data_to_plot))
## 
## Call: rlm(formula = DFR_L_IPS ~ LCD_CDA_1dots, data = data_to_plot)
## Residuals:
##        Min         1Q     Median         3Q        Max 
## -0.7641806 -0.1333044  0.0006503  0.1412663  0.8825566 
## 
## Coefficients:
##               Value  Std. Error t value
## (Intercept)   0.1416 0.0183     7.7444 
## LCD_CDA_1dots 0.0372 0.0324     1.1483 
## 
## Residual standard error: 0.201 on 160 degrees of freedom
##   (8 observations deleted due to missingness)
(ggplot(data_to_plot,aes(x=omnibus_span, y=LCD_CDA_5dots))+
    geom_point()+
    stat_smooth(method="lm")+
    ylim(c(-5,2.5))+
    theme_classic())+(ggplot(data_to_plot,aes(x=omnibus_span, y=LCD_CDA_3dots))+
                        geom_point()+
                        stat_smooth(method="lm")+
                        ylim(c(-5,2.5))+
                        theme_classic())+(ggplot(data_to_plot,aes(x=omnibus_span, y=LCD_CDA_1dots))+
                                            geom_point()+
                                            stat_smooth(method="lm")+
                                            ylim(c(-5,2.5))+
                                            theme_classic()+
                                            theme(aspect.ratio=1))
## `geom_smooth()` using formula 'y ~ x'
## Warning: Removed 8 rows containing non-finite values (stat_smooth).

## Warning: Removed 8 rows containing missing values (geom_point).
## `geom_smooth()` using formula 'y ~ x'
## Warning: Removed 8 rows containing non-finite values (stat_smooth).

## Warning: Removed 8 rows containing missing values (geom_point).
## `geom_smooth()` using formula 'y ~ x'
## Warning: Removed 8 rows containing non-finite values (stat_smooth).

## Warning: Removed 8 rows containing missing values (geom_point).

# cor.test(data_to_plot$LCD_CDA_5dots, data_to_plot$omnibus_span)
summary(rlm(omnibus_span ~ LCD_CDA_5dots, data = data_to_plot))
## 
## Call: rlm(formula = omnibus_span ~ LCD_CDA_5dots, data = data_to_plot)
## Residuals:
##       Min        1Q    Median        3Q       Max 
## -1.730464 -0.373881 -0.004574  0.325815  1.488930 
## 
## Coefficients:
##               Value   Std. Error t value
## (Intercept)    0.0970  0.0549     1.7671
## LCD_CDA_5dots -0.0214  0.0763    -0.2804
## 
## Residual standard error: 0.5136 on 160 degrees of freedom
##   (8 observations deleted due to missingness)
# cor.test(data_to_plot$LCD_CDA_3dots, data_to_plot$omnibus_span)
summary(rlm(omnibus_span ~ LCD_CDA_3dots, data = data_to_plot))
## 
## Call: rlm(formula = omnibus_span ~ LCD_CDA_3dots, data = data_to_plot)
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -1.73880 -0.35937 -0.03574  0.34103  1.51129 
## 
## Coefficients:
##               Value   Std. Error t value
## (Intercept)    0.0522  0.0567     0.9212
## LCD_CDA_3dots -0.1169  0.0703    -1.6612
## 
## Residual standard error: 0.5134 on 160 degrees of freedom
##   (8 observations deleted due to missingness)
# cor.test(data_to_plot$LCD_CDA_1dots, data_to_plot$omnibus_span)
summary(rlm(omnibus_span ~ LCD_CDA_1dots, data = data_to_plot))
## 
## Call: rlm(formula = omnibus_span ~ LCD_CDA_1dots, data = data_to_plot)
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -1.75828 -0.39372 -0.03161  0.34098  1.43290 
## 
## Coefficients:
##               Value   Std. Error t value
## (Intercept)    0.0948  0.0468     2.0237
## LCD_CDA_1dots -0.1116  0.0830    -1.3441
## 
## Residual standard error: 0.5604 on 160 degrees of freedom
##   (8 observations deleted due to missingness)
(ggplot(data_to_plot,aes(x=XLCD_K_MAX, y=LCD_CDA_5dots))+
    geom_point()+
    stat_smooth(method="lm")+
    ylim(c(-5,2.5))+
    theme_classic())+(ggplot(data_to_plot,aes(x=XLCD_K_MAX, y=LCD_CDA_3dots))+
                        geom_point()+
                        stat_smooth(method="lm")+
                        ylim(c(-5,2.5))+
                        theme_classic())+(ggplot(data_to_plot,aes(x=XLCD_K_MAX, y=LCD_CDA_1dots))+
                                            geom_point()+
                                            stat_smooth(method="lm")+
                                            ylim(c(-5,2.5))+
                                            theme_classic()+
                                            theme(aspect.ratio=1))
## `geom_smooth()` using formula 'y ~ x'
## Warning: Removed 9 rows containing non-finite values (stat_smooth).
## Warning: Removed 9 rows containing missing values (geom_point).
## `geom_smooth()` using formula 'y ~ x'
## Warning: Removed 9 rows containing non-finite values (stat_smooth).

## Warning: Removed 9 rows containing missing values (geom_point).
## `geom_smooth()` using formula 'y ~ x'
## Warning: Removed 9 rows containing non-finite values (stat_smooth).

## Warning: Removed 9 rows containing missing values (geom_point).

# cor.test(data_to_plot$LCD_CDA_5dots, data_to_plot$XLCD_K_MAX)
summary(rlm(XLCD_K_MAX ~ LCD_CDA_5dots, data = data_to_plot))
## 
## Call: rlm(formula = XLCD_K_MAX ~ LCD_CDA_5dots, data = data_to_plot)
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -1.78438 -0.56598  0.04894  0.56305  1.93596 
## 
## Coefficients:
##               Value   Std. Error t value
## (Intercept)    2.7073  0.0824    32.8463
## LCD_CDA_5dots -0.0020  0.1144    -0.0171
## 
## Residual standard error: 0.8392 on 159 degrees of freedom
##   (9 observations deleted due to missingness)
# cor.test(data_to_plot$LCD_CDA_3dots, data_to_plot$XLCD_K_MAX)
summary(rlm(XLCD_K_MAX ~ LCD_CDA_3dots, data = data_to_plot))
## 
## Call: rlm(formula = XLCD_K_MAX ~ LCD_CDA_3dots, data = data_to_plot)
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -1.73349 -0.57816  0.02962  0.56396  2.02578 
## 
## Coefficients:
##               Value   Std. Error t value
## (Intercept)    2.6402  0.0818    32.2583
## LCD_CDA_3dots -0.1346  0.1012    -1.3299
## 
## Residual standard error: 0.8573 on 159 degrees of freedom
##   (9 observations deleted due to missingness)
# cor.test(data_to_plot$LCD_CDA_1dots, data_to_plot$XLCD_K_MAX)
summary(rlm(XLCD_K_MAX ~ LCD_CDA_1dots, data = data_to_plot))
## 
## Call: rlm(formula = XLCD_K_MAX ~ LCD_CDA_1dots, data = data_to_plot)
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -1.76883 -0.59852  0.01748  0.54606  1.74152 
## 
## Coefficients:
##               Value   Std. Error t value
## (Intercept)    2.6791  0.0706    37.9311
## LCD_CDA_1dots -0.2088  0.1249    -1.6716
## 
## Residual standard error: 0.8515 on 159 degrees of freedom
##   (9 observations deleted due to missingness)
CDA_split <- split_into_groups(CDA_fMRI, WM_groups)
CDA_split_plot_data <- prep_split_for_bar_plots(CDA_split)
CDA_split_plot_data[["melt_data"]] %>%
  filter(variable == "LCD_CDA_5dots") %>%
  mutate(level = factor(level,levels=c("low","med","high"))) %>%
  ggplot()+
  geom_bar(aes(x=level,y=Means),stat="identity")+
  geom_errorbar(aes(x=level,ymin=Means-SE,ymax=Means+SE), width=0.2)+
  xlab("WMC group")+
  ylab("CDA")+
  ggtitle("CDA - 5 dots")+ 
  theme_classic()+
  theme(aspect.ratio=1)

CDA_split_plot_data[["melt_data"]] %>%
  filter(variable == "LCD_CDA_3dots") %>%
  mutate(level = factor(level,levels=c("low","med","high"))) %>%
  ggplot()+
  geom_bar(aes(x=level,y=Means),stat="identity")+
  geom_errorbar(aes(x=level,ymin=Means-SE,ymax=Means+SE), width=0.2)+
  xlab("WMC group")+
  ylab("CDA")+
  ggtitle("CDA - 3 dots")+ 
  theme_classic()+
  theme(aspect.ratio=1)

CDA_split_plot_data[["melt_data"]] %>%
  filter(variable == "LCD_CDA_1dots") %>%
  mutate(level = factor(level,levels=c("low","med","high"))) %>%
  ggplot()+
  geom_bar(aes(x=level,y=Means),stat="identity")+
  geom_errorbar(aes(x=level,ymin=Means-SE,ymax=Means+SE), width=0.2)+
  xlab("WMC group")+
  ylab("CDA")+
  ggtitle("CDA - 1 dot")+ 
  theme_classic()+
  theme(aspect.ratio=1)

CDA_anova <- merge(CDA_fMRI,WM_to_merge, by="PTID")

summary(aov(LCD_CDA_1dots ~ level,data=CDA_anova))
##              Df Sum Sq Mean Sq F value Pr(>F)
## level         2   0.64  0.3182   1.053  0.351
## Residuals   157  47.44  0.3022               
## 8 observations deleted due to missingness
summary(aov(LCD_CDA_3dots ~ level,data=CDA_anova))
##              Df Sum Sq Mean Sq F value Pr(>F)
## level         2   1.45  0.7228   1.684  0.189
## Residuals   157  67.37  0.4291               
## 8 observations deleted due to missingness

Relationship of Load Effects with Span

Vogel and Machizawa (2004) had mean K = 2.8. Our average K max = 2.68 (so slightly lower). When we run a robust regression, we see significant relationships with DFR load effect for the 5-3 and 3-1 conditions, and for 3-1 for the L IPS load effect.

(ggplot(data_to_plot,aes(x=DFR_Load3_Load1, y=CDA_5_3))+
   geom_point()+
   stat_smooth(method="lm")+
   theme_classic())+(ggplot(data_to_plot,aes(x=DFR_Load3_Load1, y=CDA_5_1))+
                       geom_point()+
                       stat_smooth(method="lm")+
                       theme_classic())+(ggplot(data_to_plot,aes(x=DFR_Load3_Load1, y=CDA_3_1))+
                                           geom_point()+
                                           stat_smooth(method="lm")+
                                           theme_classic()+
                                           theme(aspect.ratio=1))
## `geom_smooth()` using formula 'y ~ x'
## Warning: Removed 8 rows containing non-finite values (stat_smooth).
## Warning: Removed 8 rows containing missing values (geom_point).
## `geom_smooth()` using formula 'y ~ x'
## Warning: Removed 8 rows containing non-finite values (stat_smooth).

## Warning: Removed 8 rows containing missing values (geom_point).
## `geom_smooth()` using formula 'y ~ x'
## Warning: Removed 8 rows containing non-finite values (stat_smooth).

## Warning: Removed 8 rows containing missing values (geom_point).

# cor.test(data_to_plot$CDA_5_3, data_to_plot$DFR_Load3_Load1)
# cor.test(data_to_plot$CDA_5_1, data_to_plot$DFR_Load3_Load1)
# cor.test(data_to_plot$CDA_3_1, data_to_plot$DFR_Load3_Load1)

summary(rlm(DFR_Load3_Load1 ~ CDA_3_1, data = data_to_plot))
## 
## Call: rlm(formula = DFR_Load3_Load1 ~ CDA_3_1, data = data_to_plot)
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -0.57033 -0.10804 -0.01177  0.13570  0.96805 
## 
## Coefficients:
##             Value   Std. Error t value
## (Intercept)  0.1180  0.0172     6.8504
## CDA_3_1     -0.0417  0.0206    -2.0182
## 
## Residual standard error: 0.1915 on 160 degrees of freedom
##   (8 observations deleted due to missingness)
summary(rlm(DFR_Load3_Load1 ~ CDA_5_1, data = data_to_plot))
## 
## Call: rlm(formula = DFR_Load3_Load1 ~ CDA_5_1, data = data_to_plot)
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -0.59351 -0.13272 -0.01197  0.12847  1.01566 
## 
## Coefficients:
##             Value   Std. Error t value
## (Intercept)  0.1312  0.0172     7.6242
## CDA_5_1     -0.0071  0.0218    -0.3239
## 
## Residual standard error: 0.1967 on 160 degrees of freedom
##   (8 observations deleted due to missingness)
summary(rlm(DFR_Load3_Load1 ~ CDA_5_3, data = data_to_plot))
## 
## Call: rlm(formula = DFR_Load3_Load1 ~ CDA_5_3, data = data_to_plot)
## Residuals:
##       Min        1Q    Median        3Q       Max 
## -0.571601 -0.123422 -0.001248  0.128063  1.019270 
## 
## Coefficients:
##             Value  Std. Error t value
## (Intercept) 0.1280 0.0158     8.1102 
## CDA_5_3     0.0397 0.0198     2.0002 
## 
## Residual standard error: 0.1894 on 160 degrees of freedom
##   (8 observations deleted due to missingness)
(ggplot(data_to_plot,aes(x=DFR_L_IPS, y=CDA_5_3))+
  geom_point()+
  stat_smooth(method="lm")+
  ylim(c(-5,2.5))+
  theme_classic())+(ggplot(data_to_plot,aes(x=DFR_L_IPS, y=CDA_5_1))+
                      geom_point()+
                      stat_smooth(method="lm")+
                      ylim(c(-5,2.5))+
                      theme_classic())+(ggplot(data_to_plot,aes(x=DFR_L_IPS, y=CDA_3_1))+
                                          geom_point()+
                                          stat_smooth(method="lm")+
                                          ylim(c(-5,2.5))+
                                          theme_classic()+
                                          theme(aspect.ratio=1))
## `geom_smooth()` using formula 'y ~ x'
## Warning: Removed 10 rows containing non-finite values (stat_smooth).
## Warning: Removed 10 rows containing missing values (geom_point).
## `geom_smooth()` using formula 'y ~ x'
## Warning: Removed 8 rows containing non-finite values (stat_smooth).
## Warning: Removed 8 rows containing missing values (geom_point).
## `geom_smooth()` using formula 'y ~ x'
## Warning: Removed 8 rows containing non-finite values (stat_smooth).

## Warning: Removed 8 rows containing missing values (geom_point).

# cor.test(data_to_plot$LCD_CDA_5dots, data_to_plot$DFR_L_IPS)
summary(rlm(DFR_L_IPS ~ CDA_5_3, data = data_to_plot))
## 
## Call: rlm(formula = DFR_L_IPS ~ CDA_5_3, data = data_to_plot)
## Residuals:
##       Min        1Q    Median        3Q       Max 
## -0.761952 -0.131583  0.001305  0.139002  0.889952 
## 
## Coefficients:
##             Value  Std. Error t value
## (Intercept) 0.1352 0.0176     7.6943 
## CDA_5_3     0.0206 0.0221     0.9337 
## 
## Residual standard error: 0.2025 on 160 degrees of freedom
##   (8 observations deleted due to missingness)
# cor.test(data_to_plot$LCD_CDA_3dots, data_to_plot$DFR_L_IPS)
summary(rlm(DFR_L_IPS ~ CDA_5_1, data = data_to_plot))
## 
## Call: rlm(formula = DFR_L_IPS ~ CDA_5_1, data = data_to_plot)
## Residuals:
##       Min        1Q    Median        3Q       Max 
## -0.758978 -0.129715  0.001689  0.135662  0.860938 
## 
## Coefficients:
##             Value   Std. Error t value
## (Intercept)  0.1309  0.0188     6.9718
## CDA_5_1     -0.0264  0.0238    -1.1104
## 
## Residual standard error: 0.2005 on 160 degrees of freedom
##   (8 observations deleted due to missingness)
# cor.test(data_to_plot$LCD_CDA_1dots, data_to_plot$DFR_L_IPS)
summary(rlm(DFR_L_IPS ~ CDA_3_1, data = data_to_plot))
## 
## Call: rlm(formula = DFR_L_IPS ~ CDA_3_1, data = data_to_plot)
## Residuals:
##       Min        1Q    Median        3Q       Max 
## -0.736310 -0.138672 -0.003474  0.118087  0.828247 
## 
## Coefficients:
##             Value   Std. Error t value
## (Intercept)  0.1198  0.0188     6.3561
## CDA_3_1     -0.0482  0.0226    -2.1311
## 
## Residual standard error: 0.2044 on 160 degrees of freedom
##   (8 observations deleted due to missingness)
(ggplot(data_to_plot,aes(x=omnibus_span, y=CDA_5_3))+
    geom_point()+
    stat_smooth(method="lm")+
    theme_classic())+(ggplot(data_to_plot,aes(x=omnibus_span, y=CDA_5_1))+
                        geom_point()+
                        stat_smooth(method="lm")+
                        theme_classic())+(ggplot(data_to_plot,aes(x=omnibus_span, y=CDA_3_1))+
                                            geom_point()+
                                            stat_smooth(method="lm")+
                                            theme_classic()+
                                            theme(aspect.ratio=1)
                        )
## `geom_smooth()` using formula 'y ~ x'
## Warning: Removed 8 rows containing non-finite values (stat_smooth).

## Warning: Removed 8 rows containing missing values (geom_point).
## `geom_smooth()` using formula 'y ~ x'
## Warning: Removed 8 rows containing non-finite values (stat_smooth).

## Warning: Removed 8 rows containing missing values (geom_point).
## `geom_smooth()` using formula 'y ~ x'
## Warning: Removed 8 rows containing non-finite values (stat_smooth).

## Warning: Removed 8 rows containing missing values (geom_point).

# cor.test(data_to_plot$CDA_5_3, data_to_plot$omnibus_span)
# cor.test(data_to_plot$CDA_5_1, data_to_plot$omnibus_span)
# cor.test(data_to_plot$CDA_3_1, data_to_plot$omnibus_span)

summary(rlm(omnibus_span ~ CDA_3_1, data = data_to_plot))
## 
## Call: rlm(formula = omnibus_span ~ CDA_3_1, data = data_to_plot)
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -1.76026 -0.35697 -0.00169  0.33785  1.51663 
## 
## Coefficients:
##             Value   Std. Error t value
## (Intercept)  0.0978  0.0507     1.9292
## CDA_3_1     -0.0251  0.0608    -0.4136
## 
## Residual standard error: 0.5077 on 160 degrees of freedom
##   (8 observations deleted due to missingness)
summary(rlm(omnibus_span ~ CDA_5_1, data = data_to_plot))
## 
## Call: rlm(formula = omnibus_span ~ CDA_5_1, data = data_to_plot)
## Residuals:
##       Min        1Q    Median        3Q       Max 
## -1.833921 -0.352318  0.004077  0.354097  1.494419 
## 
## Coefficients:
##             Value  Std. Error t value
## (Intercept) 0.1220 0.0479     2.5487 
## CDA_5_1     0.0459 0.0606     0.7576 
## 
## Residual standard error: 0.5268 on 160 degrees of freedom
##   (8 observations deleted due to missingness)
summary(rlm(omnibus_span ~ CDA_5_3, data = data_to_plot))
## 
## Call: rlm(formula = omnibus_span ~ CDA_5_3, data = data_to_plot)
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -1.85252 -0.34574 -0.02772  0.35912  1.53697 
## 
## Coefficients:
##             Value  Std. Error t value
## (Intercept) 0.1057 0.0459     2.3048 
## CDA_5_3     0.0647 0.0576     1.1229 
## 
## Residual standard error: 0.531 on 160 degrees of freedom
##   (8 observations deleted due to missingness)
mean(data_to_plot$XLCD_K_MAX,na.rm=TRUE)
## [1] 2.686799
(ggplot(data_to_plot,aes(x=XLCD_K_MAX, y=CDA_5_3))+
    geom_point()+
    stat_smooth(method="lm")+
    theme_classic()+
    theme(aspect.ratio=1))+(ggplot(data_to_plot,aes(x=XLCD_K_MAX, y=CDA_5_1))+
                              geom_point()+
                              stat_smooth(method="loess")+
                              theme_classic())+(ggplot(data_to_plot,aes(x=XLCD_K_MAX, y=CDA_3_1))+
                                                  geom_point()+
                                                  stat_smooth(method="loess")+
                                                  theme_classic()) 
## `geom_smooth()` using formula 'y ~ x'
## Warning: Removed 9 rows containing non-finite values (stat_smooth).
## Warning: Removed 9 rows containing missing values (geom_point).
## `geom_smooth()` using formula 'y ~ x'
## Warning: Removed 9 rows containing non-finite values (stat_smooth).

## Warning: Removed 9 rows containing missing values (geom_point).
## `geom_smooth()` using formula 'y ~ x'
## Warning: Removed 9 rows containing non-finite values (stat_smooth).

## Warning: Removed 9 rows containing missing values (geom_point).

# cor.test(data_to_plot$CDA_5_3, data_to_plot$XLCD_K_MAX)
# cor.test(data_to_plot$CDA_5_1, data_to_plot$XLCD_K_MAX)
# cor.test(data_to_plot$CDA_3_1, data_to_plot$XLCD_K_MAX)
summary(rlm(XLCD_K_MAX ~ CDA_3_1, data = data_to_plot))
## 
## Call: rlm(formula = XLCD_K_MAX ~ CDA_3_1, data = data_to_plot)
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -1.78153 -0.56832  0.04731  0.56532  1.92546 
## 
## Coefficients:
##             Value   Std. Error t value
## (Intercept)  2.7100  0.0744    36.4063
## CDA_3_1      0.0047  0.0890     0.0526
## 
## Residual standard error: 0.8414 on 159 degrees of freedom
##   (9 observations deleted due to missingness)
summary(rlm(XLCD_K_MAX ~ CDA_5_1, data = data_to_plot))
## 
## Call: rlm(formula = XLCD_K_MAX ~ CDA_5_1, data = data_to_plot)
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -1.86359 -0.51169  0.02012  0.53791  1.75303 
## 
## Coefficients:
##             Value   Std. Error t value
## (Intercept)  2.7433  0.0725    37.8139
## CDA_5_1      0.1244  0.0918     1.3554
## 
## Residual standard error: 0.7821 on 159 degrees of freedom
##   (9 observations deleted due to missingness)
summary(rlm(XLCD_K_MAX ~ CDA_5_3, data = data_to_plot))
## 
## Call: rlm(formula = XLCD_K_MAX ~ CDA_5_3, data = data_to_plot)
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -1.8204 -0.5399  0.0366  0.5651  1.9432 
## 
## Coefficients:
##             Value   Std. Error t value
## (Intercept)  2.7007  0.0658    41.0692
## CDA_5_3      0.0994  0.0826     1.2042
## 
## Residual standard error: 0.8241 on 159 degrees of freedom
##   (9 observations deleted due to missingness)
ggplot(data_to_plot,aes(x=XLCD_K_MAX, y=omnibus_span))+
  geom_point()+
  stat_smooth(method="lm")+
  theme_classic()
## `geom_smooth()` using formula 'y ~ x'
## Warning: Removed 3 rows containing non-finite values (stat_smooth).
## Warning: Removed 3 rows containing missing values (geom_point).

cor.test(data_to_plot$omnibus_span, data_to_plot$XLCD_K_MAX)
## 
##  Pearson's product-moment correlation
## 
## data:  data_to_plot$omnibus_span and data_to_plot$XLCD_K_MAX
## t = 8.8404, df = 165, p-value = 1.384e-15
## alternative hypothesis: true correlation is not equal to 0
## 95 percent confidence interval:
##  0.4541707 0.6618156
## sample estimates:
##       cor 
## 0.5669319

Numerically, it looks like there is an inverted U shaped relationship for the 5 dots - 1 dot and 3 dot - 1 dot, but those relationships are not significant.

CDA_split_plot_data[["melt_data"]] %>%
  filter(variable == "CDA_5_3") %>%
  mutate(level = factor(level,levels=c("low","med","high"))) %>%
  ggplot()+
  geom_bar(aes(x=level,y=Means),stat="identity")+
  geom_errorbar(aes(x=level,ymin=Means-SE,ymax=Means+SE), width=0.2)+
  xlab("WMC group")+
  ylab("CDA Load Effect")+
  ggtitle("5 dots - 3 dots")+ 
  theme_classic()+
  theme(aspect.ratio=1)

CDA_split_plot_data[["melt_data"]] %>%
  filter(variable == "CDA_5_1") %>%
  mutate(level = factor(level,levels=c("low","med","high"))) %>%
  ggplot()+
  geom_bar(aes(x=level,y=Means),stat="identity")+
  geom_errorbar(aes(x=level,ymin=Means-SE,ymax=Means+SE), width=0.2)+
  xlab("WMC group")+
  ylab("CDA Load Effect")+
  ggtitle("5 dots - 1 dot")+ 
  theme_classic()+
  theme(aspect.ratio=1)

CDA_split_plot_data[["melt_data"]] %>%
  filter(variable == "CDA_3_1") %>%
  mutate(level = factor(level,levels=c("low","med","high"))) %>%
  ggplot()+
  geom_bar(aes(x=level,y=Means),stat="identity")+
  geom_errorbar(aes(x=level,ymin=Means-SE,ymax=Means+SE), width=0.2)+
  xlab("WMC group")+
  ylab("CDA Load Effect")+
  ggtitle("3 dots - 1 dot")+ 
  theme_classic()+
  theme(aspect.ratio=1)

CDA_5_3.aov <- aov(CDA_5_3 ~ level, data = CDA_anova)
print("CDA - 5 dots - 3 dots")
## [1] "CDA - 5 dots - 3 dots"
print(summary(CDA_5_3.aov))
##              Df Sum Sq Mean Sq F value Pr(>F)
## level         2   1.41  0.7053   1.112  0.331
## Residuals   157  99.58  0.6343               
## 8 observations deleted due to missingness
CDA_5_1.aov <- aov(CDA_5_1 ~ level, data = CDA_anova)
print("CDA - 5 dots - 1 dot")
## [1] "CDA - 5 dots - 1 dot"
print(summary(CDA_5_1.aov))
##              Df Sum Sq Mean Sq F value Pr(>F)
## level         2   0.53   0.263   0.465  0.629
## Residuals   157  88.86   0.566               
## 8 observations deleted due to missingness
CDA_3_1.aov <- aov(CDA_3_1 ~ level, data = CDA_anova)
print("CDA - 3 dots - 1 dot")
## [1] "CDA - 3 dots - 1 dot"
print(summary(CDA_3_1.aov))
##              Df Sum Sq Mean Sq F value Pr(>F)
## level         2   2.12  1.0607   1.797  0.169
## Residuals   157  92.68  0.5903               
## 8 observations deleted due to missingness

Correlations between EEG and fMRI

p200_delay_DFR$PTID <- p200_delay_avgs$PTID 

fMRI_measures <- Reduce(function(x,y) merge(x,y,by="PTID"), 
                        list(p200_delay_DFR, p200_FFA, p200_cue_avgs))

fMRI_measures$CUE_L1_avg <- rowMeans(cbind(fMRI_measures$R_CUE_L1,fMRI_measures$L_CUE_L1))
fMRI_measures$DELAY_L1_avg <- rowMeans(cbind(fMRI_measures$R_DELAY_L1,fMRI_measures$L_DELAY_L1))
fMRI_measures$PROBE_L1_avg <- rowMeans(cbind(fMRI_measures$R_PROBE_L1,fMRI_measures$L_PROBE_L1))

fMRI_measures$CUE_L3_avg <- rowMeans(cbind(fMRI_measures$R_CUE_L3,fMRI_measures$L_CUE_L3))
fMRI_measures$DELAY_L3_avg <- rowMeans(cbind(fMRI_measures$R_DELAY_L3,fMRI_measures$L_DELAY_L3))
fMRI_measures$PROBE_L3_avg <- rowMeans(cbind(fMRI_measures$R_PROBE_L3,fMRI_measures$L_PROBE_L3))

fMRI_measures$CUE_LE_avg <- rowMeans(cbind(fMRI_measures$R_CUE_LE,fMRI_measures$L_CUE_LE))
fMRI_measures$DELAY_LE_avg <- rowMeans(cbind(fMRI_measures$R_DELAY_LE,fMRI_measures$L_DELAY_LE))
fMRI_measures$PROBE_LE_avg <- rowMeans(cbind(fMRI_measures$R_PROBE_LE,fMRI_measures$L_PROBE_LE))

ERP_measures <- Reduce(function(x,y) merge(x, y, by ="PTID"), 
                       list(cue_average_midOccip_n170, cue_average_P3, 
                            probe_average_midOccip_n170, probe_average_P3))

colnames(ERP_measures) <- c("PTID", "low_load_cue_midOccip_n170", "high_load_cue_midOccip_n170", "load_effect_cue_midOccip_n170", "low_load_cue_P3", "high_load_cue_P3", "load_effect_cue_P3", "low_load_probe_midOccip_n170", "high_load_probe_midOccip_n170", "load_effect_probe_midOccip_n170", "low_load_probe_P3", "high_load_probe_P3", "load_effect_probe_P3")

ERSP_measures_alpha <- Reduce(function(x,y) merge(x,y,by="PTID"), 
                              list(alpha_cue_average_midOccip,
                                   alpha_delay_average_midOccip,
                                   alpha_cue_average_Oz, 
                                   alpha_delay_average_Oz, 
                                   alpha_probe_average_midOccip, 
                                   alpha_probe_average_Oz))


colnames(ERSP_measures_alpha) <- c("PTID","high_alpha_cue_midOccip", "low_alpha_cue_midOccip", "LE_alpha_cue_midOccip", "high_alpha_delay_midOccip", "low_alpha_delay_midOccip", "LE_alpha_delay_midOccip", "high_alpha_cue_Oz", "low_alpha_cue_Oz", "LE_alpha_cue_Oz", "high_alpha_delay_Oz", "low_alpha_delay_Oz", "LE_alpha_delay_Oz", "high_alpha_probe_midOccip", "low_alpha_probe_midOccip", "LE_alpha_probe_midOccip","high_alpha_probe_Oz", "low_alpha_probe_Oz", "LE_alpha_probe_Oz" )

ERSP_measures_beta <- Reduce(function(x,y) merge(x,y,by="PTID"), 
                             list(beta_cue_average_midOccip,
                                  beta_delay_average_midOccip,
                                  beta_cue_average_Oz, 
                                  beta_delay_average_Oz, 
                                  beta_probe_average_midOccip, 
                                  beta_probe_average_Oz))


colnames(ERSP_measures_beta) <- c("PTID","high_beta_cue_midOccip", "low_beta_cue_midOccip", "LE_beta_cue_midOccip", "high_beta_delay_midOccip", "low_beta_delay_midOccip", "LE_beta_delay_midOccip", "high_beta_cue_Oz", "low_beta_cue_Oz", "LE_beta_cue_Oz", "high_beta_delay_Oz", "low_beta_delay_Oz", "LE_beta_delay_Oz", "high_beta_probe_midOccip", "low_beta_probe_midOccip", "LE_beta_probe_midOccip","high_beta_probe_Oz", "low_beta_probe_Oz", "LE_beta_probe_Oz" )

ERSP_measures <- merge(ERSP_measures_alpha, ERSP_measures_beta, by= "PTID")

ERPs

ERP_fMRI_plots <- list()

ERP_fMRI <- merge(fMRI_measures, ERP_measures, by= "PTID")
sig_linear_ERP_fMRI <- list()

cumulative_df_ERP <- data.frame(matrix(nrow=1,ncol=4))
colnames(cumulative_df_ERP) <- c("ERP_measure", "fMRI_measure", "corr", "p_val")

plot_count <- 1
sig_plot_count <- 1
for (ERP in c(36:45)){
  for (fMRI in c(2:4,23,25:33)){
    ERP_fMRI_plots[[plot_count]] <- ggplot(ERP_fMRI, aes_string(y=colnames(ERP_fMRI)[ERP],x=colnames(ERP_fMRI)[fMRI]))+
      geom_point()+
      stat_smooth(method="lm")+
      theme_classic()+
      theme(aspect.ratio=1)
    
    cor_results <- cor.test(ERP_fMRI[,ERP], ERP_fMRI[,fMRI])
    if (cor_results$p.value < 0.05){
      sig_linear_ERP_fMRI[[sig_plot_count]] <- ERP_fMRI_plots[[plot_count]]
      sig_plot_count <- sig_plot_count +1 
      cumulative_df_ERP <- rbind(cumulative_df_ERP, c(colnames(ERP_fMRI)[ERP], colnames(ERP_fMRI)[fMRI], cor_results$estimate, cor_results$p.value))
    } 
    plot_count <- plot_count+1
  }
}

ERP vs fMRI

It’s hard to interpret these since none of them are comparing like, but just wanted to leave it here for the record.

cumulative_df_ERP <- cumulative_df_ERP[2:nrow(cumulative_df_ERP),]

cumulative_df_ERP %>% 
  kable(format = "html", escape = F) %>%
  kable_styling("striped", full_width = F) 
ERP_measure fMRI_measure corr p_val
2 load_effect_cue_midOccip_n170 CUE_L1_avg 0.168360585458305 0.0374979529251927
3 low_load_cue_P3 CUE_LE_avg 0.182757533804539 0.0237514841131259
4 load_effect_cue_P3 DELAY_L3_avg 0.209448914546025 0.00936647450051395
5 high_load_probe_P3 DFR_Load3_Load1 -0.17219145504146 0.0333082803235829
6 high_load_probe_P3 DELAY_L1_avg 0.180678759270006 0.0254191873879704
7 load_effect_probe_P3 DELAY_L1_avg 0.186714147764717 0.0208357542948427
8 load_effect_probe_P3 CUE_L3_avg -0.201741313033054 0.0123946284661481
9 load_effect_probe_P3 PROBE_L3_avg -0.183907436137367 0.0228699996014812
10 load_effect_probe_P3 CUE_LE_avg -0.203552413827566 0.011614854390257
for (idx in seq.int(1,length(sig_linear_ERP_fMRI))){
  print(sig_linear_ERP_fMRI[[idx]])
}
## `geom_smooth()` using formula 'y ~ x'

## `geom_smooth()` using formula 'y ~ x'

## `geom_smooth()` using formula 'y ~ x'

## `geom_smooth()` using formula 'y ~ x'

## `geom_smooth()` using formula 'y ~ x'

## `geom_smooth()` using formula 'y ~ x'

## `geom_smooth()` using formula 'y ~ x'

## `geom_smooth()` using formula 'y ~ x'

## `geom_smooth()` using formula 'y ~ x'

ERSP vs fMRI

ERSP_fMRI_plots <- list()

ERSP_fMRI <- merge(fMRI_measures, ERSP_measures, by= "PTID")
sig_linear_ERSP_fMRI <- list()

cumulative_df_ERSP <- data.frame(matrix(nrow=1,ncol=4))
colnames(cumulative_df_ERSP) <- c("ERSP_measure", "fMRI_measure", "corr", "p_value")

plot_count <- 1
sig_plot_count <- 1
for (ERSP in seq.int(34,69)){
  for (fMRI in c(2:4,23,25:33)){
    ERSP_fMRI_plots[[plot_count]] <- ggplot(ERSP_fMRI, aes_string(y=colnames(ERSP_fMRI)[ERSP],x=colnames(ERSP_fMRI)[fMRI]))+
      geom_point()+
      stat_smooth(method="lm")+
      theme_classic()+
      theme(aspect.ratio=1)
    
    cor_results <- cor.test(ERSP_fMRI[,ERSP], ERSP_fMRI[,fMRI])
    if (cor_results$p.value < 0.05){
      sig_linear_ERSP_fMRI[[sig_plot_count]] <- ERSP_fMRI_plots[[plot_count]]
      sig_plot_count <- sig_plot_count +1 
      cumulative_df_ERSP <- rbind(cumulative_df_ERSP, c(colnames(ERSP_fMRI)[ERSP], colnames(ERSP_fMRI)[fMRI], cor_results$estimate, cor_results$p.value))
      
    } 
    plot_count <- plot_count+1
  }
}

Linear Correlations

Again, hard to interpret because none of the comparisons are like to like, but putting them here.

cumulative_df_ERSP <- cumulative_df_ERSP[2:nrow(cumulative_df_ERSP),]

cumulative_df_ERSP %>% 
  kable(format = "html", escape = F) %>%
  kable_styling("striped", full_width = F) 
ERSP_measure fMRI_measure corr p_value
2 high_alpha_cue_Oz DELAY_LE_avg -0.195597658214643 0.0153920599549651
3 low_alpha_cue_Oz DELAY_LE_avg -0.160355282891383 0.0476977295004719
4 LE_alpha_probe_midOccip CUE_LE_avg -0.165509017536118 0.0408975051746419
5 LE_alpha_probe_midOccip PROBE_LE_avg -0.172061892191283 0.0334432088841289
6 high_alpha_probe_Oz DFR_Load1_Delay -0.179251747539999 0.0266212278140106
7 high_alpha_probe_Oz DFR_Load3_Load1 0.233266911731895 0.00370987103981297
8 high_alpha_probe_Oz PROBE_L1_avg 0.195132672522671 0.0156427050842079
9 low_alpha_probe_Oz PROBE_L1_avg 0.174102505040299 0.0313710424672385
10 low_alpha_probe_Oz PROBE_L3_avg 0.184809793530868 0.0221981190016223
11 high_beta_cue_Oz DELAY_L1_avg 0.202390385426209 0.0121100450391189
12 high_beta_cue_Oz DELAY_LE_avg -0.189229324415883 0.0191474103106513
13 low_beta_cue_Oz DELAY_LE_avg -0.226001298924605 0.00496965081505567
14 LE_beta_cue_Oz CUE_L1_avg -0.178065719164808 0.0276569492321301
15 LE_beta_cue_Oz CUE_L3_avg -0.203629591326382 0.0115826047756051
16 high_beta_delay_Oz DELAY_L1_avg 0.194487733682514 0.0159962332055423
17 high_beta_delay_Oz CUE_LE_avg -0.166728058042473 0.0394138136897848
18 low_beta_delay_Oz DELAY_L1_avg 0.172184177159515 0.0333158473681164
19 low_beta_delay_Oz DELAY_LE_avg -0.205860242356547 0.010683866692058
20 LE_beta_delay_Oz CUE_L3_avg -0.162708514030265 0.0444841669412535
21 LE_beta_delay_Oz CUE_LE_avg -0.224067516774703 0.00536390601194615
22 LE_beta_delay_Oz PROBE_LE_avg -0.202270814991249 0.0121620353649241
23 low_beta_probe_Oz CUE_L1_avg 0.164980670469936 0.0415549595063139
24 low_beta_probe_Oz PROBE_L1_avg 0.212815139999981 0.00826334091584939
25 low_beta_probe_Oz CUE_L3_avg 0.181534095278279 0.0247212229547039
26 low_beta_probe_Oz PROBE_L3_avg 0.192985022863488 0.0168470462878643
for (idx in seq.int(1,length(sig_linear_ERSP_fMRI))){
  print(sig_linear_ERSP_fMRI[[idx]])
}
## `geom_smooth()` using formula 'y ~ x'

## `geom_smooth()` using formula 'y ~ x'

## `geom_smooth()` using formula 'y ~ x'

## `geom_smooth()` using formula 'y ~ x'

## `geom_smooth()` using formula 'y ~ x'

## `geom_smooth()` using formula 'y ~ x'

## `geom_smooth()` using formula 'y ~ x'

## `geom_smooth()` using formula 'y ~ x'

## `geom_smooth()` using formula 'y ~ x'

## `geom_smooth()` using formula 'y ~ x'

## `geom_smooth()` using formula 'y ~ x'

## `geom_smooth()` using formula 'y ~ x'

## `geom_smooth()` using formula 'y ~ x'

## `geom_smooth()` using formula 'y ~ x'

## `geom_smooth()` using formula 'y ~ x'

## `geom_smooth()` using formula 'y ~ x'

## `geom_smooth()` using formula 'y ~ x'

## `geom_smooth()` using formula 'y ~ x'

## `geom_smooth()` using formula 'y ~ x'

## `geom_smooth()` using formula 'y ~ x'

## `geom_smooth()` using formula 'y ~ x'

## `geom_smooth()` using formula 'y ~ x'

## `geom_smooth()` using formula 'y ~ x'

## `geom_smooth()` using formula 'y ~ x'

## `geom_smooth()` using formula 'y ~ x'

# PC data

PC_data <- read_excel("data/Data_PCscores.xlsx")
PC_merge <- merge(PC_data, constructs_fMRI, by="PTID")
PC_merge <- merge(PC_merge, WM_groups[["all"]])
EEG_acc <- read.csv("data/RDoC_Qry_DFREEG_Summary.csv")
PC_merge <- merge(PC_merge, EEG_acc, by.x="PTID", by.y="XSUB")
PC_merge$XDFR_EEG_ACC_LE <- PC_merge$XDFR_EEG_ACC_L3-PC_merge$XDFR_EEG_ACC_L1
PC_merge <- merge(PC_merge, p200_data)
PC_merge$group_label <- "NCS"
PC_merge$group_label[PC_merge$group == 1] <- "CS"

We do see significant correlations with our span measure and Cowan’s K and accuracy at high load, but not for the load effect. Interestingly, there’s a relatively low correlation between accuracy across modalities, but that is driven by the CS group. In fact, the correlation between the tasks in the NCS group is nearly 0. [[1 = CS, 2 = NCS]]

In addition, we see significant correlations between span and FAC1_RT_TaskPerf_EEGonly, FAC2_Capacity_TaskPerf_EEGOnly, Update_Alpha_FAC1, Update_P3_FAC1, storage_gamma_fac3_DFR, Alerting_SCAP_P2fixn_Fz_allloads

cor.test(PC_merge$omnibus_span_no_DFR, PC_merge$XDFR_EEG_COW_L3)
## 
##  Pearson's product-moment correlation
## 
## data:  PC_merge$omnibus_span_no_DFR and PC_merge$XDFR_EEG_COW_L3
## t = 2.1966, df = 165, p-value = 0.02944
## alternative hypothesis: true correlation is not equal to 0
## 95 percent confidence interval:
##  0.01713422 0.31242534
## sample estimates:
##       cor 
## 0.1685592
ggplot(data = PC_merge, aes(x=omnibus_span_no_DFR, y = XDFR_EEG_COW_L3))+
  geom_point()+
  stat_smooth(method="lm")+
  theme_classic()
## `geom_smooth()` using formula 'y ~ x'

cor.test(PC_merge$omnibus_span_no_DFR, PC_merge$XDFR_EEG_ACC_LE)
## 
##  Pearson's product-moment correlation
## 
## data:  PC_merge$omnibus_span_no_DFR and PC_merge$XDFR_EEG_ACC_LE
## t = -0.77801, df = 165, p-value = 0.4377
## alternative hypothesis: true correlation is not equal to 0
## 95 percent confidence interval:
##  -0.21038939  0.09225315
## sample estimates:
##         cor 
## -0.06045744
ggplot(data = PC_merge, aes(x=omnibus_span_no_DFR, y = XDFR_EEG_ACC_LE))+
  geom_point()+
  stat_smooth(method="lm")+
  theme_classic()
## `geom_smooth()` using formula 'y ~ x'

cor.test(PC_merge$omnibus_span_no_DFR, PC_merge$XDFR_EEG_ACC_L3)
## 
##  Pearson's product-moment correlation
## 
## data:  PC_merge$omnibus_span_no_DFR and PC_merge$XDFR_EEG_ACC_L3
## t = 2.7815, df = 165, p-value = 0.006041
## alternative hypothesis: true correlation is not equal to 0
## 95 percent confidence interval:
##  0.06175487 0.35217847
## sample estimates:
##       cor 
## 0.2116337
ggplot(data = PC_merge, aes(x=omnibus_span_no_DFR, y = XDFR_EEG_ACC_L3))+
  geom_point()+
  stat_smooth(method="lm")+
  theme_classic()
## `geom_smooth()` using formula 'y ~ x'

cor.test(PC_merge$XDFR_EEG_ACC_L3, PC_merge$XDFR_MRI_ACC_L3)
## 
##  Pearson's product-moment correlation
## 
## data:  PC_merge$XDFR_EEG_ACC_L3 and PC_merge$XDFR_MRI_ACC_L3
## t = 3.7603, df = 165, p-value = 0.0002353
## alternative hypothesis: true correlation is not equal to 0
## 95 percent confidence interval:
##  0.134835 0.415099
## sample estimates:
##       cor 
## 0.2809458
cor.test(PC_merge$XDFR_EEG_ACC_L3[PC_merge$group_label=="CS"],PC_merge$XDFR_MRI_ACC_L3[PC_merge$group_label=="CS"] )
## 
##  Pearson's product-moment correlation
## 
## data:  PC_merge$XDFR_EEG_ACC_L3[PC_merge$group_label == "CS"] and PC_merge$XDFR_MRI_ACC_L3[PC_merge$group_label == "CS"]
## t = 4.0007, df = 113, p-value = 0.0001131
## alternative hypothesis: true correlation is not equal to 0
## 95 percent confidence interval:
##  0.1807867 0.5029104
## sample estimates:
##       cor 
## 0.3522367
cor.test(PC_merge$XDFR_EEG_ACC_L3[PC_merge$group_label=="NCS"],PC_merge$XDFR_MRI_ACC_L3[PC_merge$group_label=="NCS"] )
## 
##  Pearson's product-moment correlation
## 
## data:  PC_merge$XDFR_EEG_ACC_L3[PC_merge$group_label == "NCS"] and PC_merge$XDFR_MRI_ACC_L3[PC_merge$group_label == "NCS"]
## t = 0.37229, df = 50, p-value = 0.7112
## alternative hypothesis: true correlation is not equal to 0
## 95 percent confidence interval:
##  -0.2235302  0.3208737
## sample estimates:
##        cor 
## 0.05257743
ggplot(data = PC_merge, aes(x=XDFR_MRI_ACC_L3, y = XDFR_EEG_ACC_L3, color=group_label))+
  geom_point()+
  stat_smooth(method="lm")+
  theme_classic()
## `geom_smooth()` using formula 'y ~ x'

for (col in seq.int(11,23)){ 
  print(colnames(PC_merge)[col])
  print(cor.test(PC_merge$omnibus_span_no_DFR, PC_merge[,col]))
  print(ggplot(data = PC_merge, aes_string(x="omnibus_span_no_DFR", y = colnames(PC_merge)[col]))+
          geom_point()+
          stat_smooth(method="lm")+
          theme_classic())
}
## [1] "FAC1_RT_TaskPerf_EEGonly"
## 
##  Pearson's product-moment correlation
## 
## data:  PC_merge$omnibus_span_no_DFR and PC_merge[, col]
## t = -2.376, df = 163, p-value = 0.01866
## alternative hypothesis: true correlation is not equal to 0
## 95 percent confidence interval:
##  -0.32661797 -0.03104903
## sample estimates:
##        cor 
## -0.1829647
## `geom_smooth()` using formula 'y ~ x'
## Warning: Removed 2 rows containing non-finite values (stat_smooth).
## Warning: Removed 2 rows containing missing values (geom_point).

## [1] "FAC2_Capacity_TaskPerf_EEGOnly"
## 
##  Pearson's product-moment correlation
## 
## data:  PC_merge$omnibus_span_no_DFR and PC_merge[, col]
## t = 10.725, df = 163, p-value < 2.2e-16
## alternative hypothesis: true correlation is not equal to 0
## 95 percent confidence interval:
##  0.5438627 0.7247615
## sample estimates:
##       cor 
## 0.6432006
## `geom_smooth()` using formula 'y ~ x'
## Warning: Removed 2 rows containing non-finite values (stat_smooth).

## Warning: Removed 2 rows containing missing values (geom_point).

## [1] "Update_Alpha_FAC1"
## 
##  Pearson's product-moment correlation
## 
## data:  PC_merge$omnibus_span_no_DFR and PC_merge[, col]
## t = -1.9896, df = 149, p-value = 0.04847
## alternative hypothesis: true correlation is not equal to 0
## 95 percent confidence interval:
##  -0.312567905 -0.001172744
## sample estimates:
##        cor 
## -0.1608711
## `geom_smooth()` using formula 'y ~ x'
## Warning: Removed 16 rows containing non-finite values (stat_smooth).
## Warning: Removed 16 rows containing missing values (geom_point).

## [1] "Update_P3_FAC1"
## 
##  Pearson's product-moment correlation
## 
## data:  PC_merge$omnibus_span_no_DFR and PC_merge[, col]
## t = 3.6797, df = 156, p-value = 0.0003211
## alternative hypothesis: true correlation is not equal to 0
## 95 percent confidence interval:
##  0.1322971 0.4201987
## sample estimates:
##       cor 
## 0.2825998
## `geom_smooth()` using formula 'y ~ x'
## Warning: Removed 9 rows containing non-finite values (stat_smooth).
## Warning: Removed 9 rows containing missing values (geom_point).

## [1] "Storage_gamma_FAC1_DPXLCD_occ"
## 
##  Pearson's product-moment correlation
## 
## data:  PC_merge$omnibus_span_no_DFR and PC_merge[, col]
## t = 0.077173, df = 128, p-value = 0.9386
## alternative hypothesis: true correlation is not equal to 0
## 95 percent confidence interval:
##  -0.1655595  0.1787971
## sample estimates:
##         cor 
## 0.006821006
## `geom_smooth()` using formula 'y ~ x'
## Warning: Removed 37 rows containing non-finite values (stat_smooth).
## Warning: Removed 37 rows containing missing values (geom_point).

## [1] "Storage_gamma_FAC2_SCAP"
## 
##  Pearson's product-moment correlation
## 
## data:  PC_merge$omnibus_span_no_DFR and PC_merge[, col]
## t = -0.60658, df = 128, p-value = 0.5452
## alternative hypothesis: true correlation is not equal to 0
## 95 percent confidence interval:
##  -0.2236623  0.1197520
## sample estimates:
##         cor 
## -0.05353803
## `geom_smooth()` using formula 'y ~ x'
## Warning: Removed 37 rows containing non-finite values (stat_smooth).

## Warning: Removed 37 rows containing missing values (geom_point).

## [1] "Storage_gamma_FAC3_DFR"
## 
##  Pearson's product-moment correlation
## 
## data:  PC_merge$omnibus_span_no_DFR and PC_merge[, col]
## t = -3.683, df = 128, p-value = 0.0003388
## alternative hypothesis: true correlation is not equal to 0
## 95 percent confidence interval:
##  -0.4573544 -0.1450922
## sample estimates:
##       cor 
## -0.309545
## `geom_smooth()` using formula 'y ~ x'
## Warning: Removed 37 rows containing non-finite values (stat_smooth).

## Warning: Removed 37 rows containing missing values (geom_point).

## [1] "Storage_gamma_FAC4_DPXLCD_frn"
## 
##  Pearson's product-moment correlation
## 
## data:  PC_merge$omnibus_span_no_DFR and PC_merge[, col]
## t = 1.4691, df = 128, p-value = 0.1443
## alternative hypothesis: true correlation is not equal to 0
## 95 percent confidence interval:
##  -0.04440393  0.29442483
## sample estimates:
##       cor 
## 0.1287667
## `geom_smooth()` using formula 'y ~ x'
## Warning: Removed 37 rows containing non-finite values (stat_smooth).

## Warning: Removed 37 rows containing missing values (geom_point).

## [1] "Storage_LCD_CDA"
## 
##  Pearson's product-moment correlation
## 
## data:  PC_merge$omnibus_span_no_DFR and PC_merge[, col]
## t = -1.5002, df = 162, p-value = 0.1355
## alternative hypothesis: true correlation is not equal to 0
## 95 percent confidence interval:
##  -0.26553968  0.03685791
## sample estimates:
##        cor 
## -0.1170531
## `geom_smooth()` using formula 'y ~ x'
## Warning: Removed 3 rows containing non-finite values (stat_smooth).
## Warning: Removed 3 rows containing missing values (geom_point).

## [1] "Storage_DFR_n170"
## 
##  Pearson's product-moment correlation
## 
## data:  PC_merge$omnibus_span_no_DFR and PC_merge[, col]
## t = 1.0341, df = 164, p-value = 0.3026
## alternative hypothesis: true correlation is not equal to 0
## 95 percent confidence interval:
##  -0.07272304  0.22999180
## sample estimates:
##        cor 
## 0.08049008
## `geom_smooth()` using formula 'y ~ x'
## Warning: Removed 1 rows containing non-finite values (stat_smooth).
## Warning: Removed 1 rows containing missing values (geom_point).

## [1] "Main_DPX_CNV_FCz_ACues"
## 
##  Pearson's product-moment correlation
## 
## data:  PC_merge$omnibus_span_no_DFR and PC_merge[, col]
## t = -1.0301, df = 160, p-value = 0.3045
## alternative hypothesis: true correlation is not equal to 0
## 95 percent confidence interval:
##  -0.23245461  0.07395252
## sample estimates:
##         cor 
## -0.08116852
## `geom_smooth()` using formula 'y ~ x'
## Warning: Removed 5 rows containing non-finite values (stat_smooth).
## Warning: Removed 5 rows containing missing values (geom_point).

## [1] "Alerting_SCAP_P2fixn_Fz_allloads"
## 
##  Pearson's product-moment correlation
## 
## data:  PC_merge$omnibus_span_no_DFR and PC_merge[, col]
## t = 2.0937, df = 165, p-value = 0.03782
## alternative hypothesis: true correlation is not equal to 0
## 95 percent confidence interval:
##  0.009231022 0.305274784
## sample estimates:
##       cor 
## 0.1608691
## `geom_smooth()` using formula 'y ~ x'

## [1] "LTM_theta_FAC1"
## 
##  Pearson's product-moment correlation
## 
## data:  PC_merge$omnibus_span_no_DFR and PC_merge[, col]
## t = 1.4856, df = 133, p-value = 0.1398
## alternative hypothesis: true correlation is not equal to 0
## 95 percent confidence interval:
##  -0.04210514  0.29044838
## sample estimates:
##       cor 
## 0.1277609
## `geom_smooth()` using formula 'y ~ x'
## Warning: Removed 32 rows containing non-finite values (stat_smooth).
## Warning: Removed 32 rows containing missing values (geom_point).

If we look at the actual interaction, it only trends towards significance.

acc_mod <- lm(XDFR_EEG_ACC_L3 ~ XDFR_MRI_ACC_L3 * group_label, data = PC_merge)
summary(acc_mod)
## 
## Call:
## lm(formula = XDFR_EEG_ACC_L3 ~ XDFR_MRI_ACC_L3 * group_label, 
##     data = PC_merge)
## 
## Residuals:
##       Min        1Q    Median        3Q       Max 
## -0.173184 -0.047774 -0.001855  0.046894  0.202637 
## 
## Coefficients:
##                                Estimate Std. Error t value Pr(>|t|)    
## (Intercept)                     0.55261    0.04849  11.396  < 2e-16 ***
## XDFR_MRI_ACC_L3                 0.27188    0.06571   4.138 5.61e-05 ***
## group_labelNCS                  0.18414    0.09395   1.960   0.0517 .  
## XDFR_MRI_ACC_L3:group_labelNCS -0.23562    0.12479  -1.888   0.0608 .  
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.07292 on 163 degrees of freedom
## Multiple R-squared:  0.1011, Adjusted R-squared:  0.08456 
## F-statistic: 6.111 on 3 and 163 DF,  p-value: 0.0005773
interact_plot(acc_mod, pred = XDFR_MRI_ACC_L3, modx =group_label)

PC_merge <- merge(PC_merge, p200_delay_DFR)

ggplot(data = PC_merge, aes(x=DFR_Load3_Load1, y=Main_DPX_CNV_FCz_ACues))+
  geom_point()+
  stat_smooth(method="lm")+
  theme_classic()
## `geom_smooth()` using formula 'y ~ x'
## Warning: Removed 5 rows containing non-finite values (stat_smooth).
## Warning: Removed 5 rows containing missing values (geom_point).

summary(rlm(Main_DPX_CNV_FCz_ACues ~ DFR_Load3_Load1, data = PC_merge))
## 
## Call: rlm(formula = Main_DPX_CNV_FCz_ACues ~ DFR_Load3_Load1, data = PC_merge)
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -2.15295 -0.45371 -0.01883  0.50152  1.83477 
## 
## Coefficients:
##                 Value   Std. Error t value
## (Intercept)     -0.4702  0.0693    -6.7895
## DFR_Load3_Load1 -0.2982  0.2604    -1.1453
## 
## Residual standard error: 0.7201 on 160 degrees of freedom
##   (5 observations deleted due to missingness)
PC_ordered <- PC_data[PC_data$PTID %in% constructs_fMRI$PTID,]
PC_ordered <- PC_ordered[order(PC_ordered$FAC2_Capacity_TaskPerf_EEGOnly),]

PC_ordered$WMC <- NA
PC_ordered$WMC[1:56] <- "low"
PC_ordered$WMC[58:113] <- "med"
PC_ordered$WMC[115:170] <- "high"
PC_ordered$WMC <- factor(PC_ordered$WMC, levels = c("low", "med", "high"))

EEG_WMC <- PC_ordered[,c(1,5,17)]

se <- function(x) {
  sd(x,na.rm=TRUE)/sqrt(length(x[!is.na(x)])) 
}


merge(EEG_WMC, p200_DFR_full_mask, by = "PTID") %>%
  filter(!is.na(WMC)) %>%
  group_by(WMC) %>%
  summarise(mean_act = mean(delay_loadEffect), se_act = se(delay_loadEffect),se_min = mean_act-se_act, se_max = mean_act+se_act) %>% 
  ggplot(aes(x=WMC, y = mean_act))+
  geom_bar(stat="identity")+
  geom_errorbar(aes(ymin=se_min, ymax=se_max), width=0.2)+
  theme_classic()+
  ylab("DFR Delay Load Effect")+
  scale_fill_discrete()
## `summarise()` ungrouping output (override with `.groups` argument)

merge(EEG_WMC, p200_DFR_full_mask, by = "PTID")  %>% 
  ggplot(aes(x=FAC2_Capacity_TaskPerf_EEGOnly, y = delay_loadEffect))+
  geom_point(aes(color=WMC))+
  ylab("DFR Delay Load Effect")+
  stat_smooth(method="loess")+
  theme_classic()
## `geom_smooth()` using formula 'y ~ x'
## Warning: Removed 3 rows containing non-finite values (stat_smooth).
## Warning: Removed 3 rows containing missing values (geom_point).

merge(constructs_fMRI, p200_DFR_full_mask, by = "PTID")  %>% 
  merge(WM_groups[["all"]], by="PTID") %>%
  ggplot(aes(x=omnibus_span_no_DFR, y = delay_loadEffect))+
  geom_point(aes(color=level))+
  stat_smooth(method="loess")+
  ylab("DFR Delay Load Effect")+
  theme_classic()
## `geom_smooth()` using formula 'y ~ x'

check_span_groups <- merge(constructs_fMRI, EEG_WMC, by = "PTID")

check_span_groups<- check_span_groups[order(check_span_groups$omnibus_span_no_DFR),]
check_span_groups$omnibus <- "low"
check_span_groups$omnibus[] <- "not_incl"
check_span_groups$omnibus[58:113] <- "med"
check_span_groups$omnibus[114] <- "not_incl"
check_span_groups$omnibus[115:170] <- "high"

check_span_groups<- check_span_groups[order(check_span_groups$FAC2_Capacity_TaskPerf_EEGOnly),]
check_span_groups$EEG <- "low"
check_span_groups$EEG[57] <- "not_incl"
check_span_groups$EEG[58:113] <- "med"
check_span_groups$EEG[114] <- "not_incl"
check_span_groups$EEG[115:170] <- "high"

sum(check_span_groups$omnibus != check_span_groups$EEG, na.rm=TRUE)
## [1] 117

These are mostly linear - the only thing that shows a numerically inverted U trend is the Storage - DFR - n170 PC, but it isn’t statistically significant.

temp_data <-  merge(PC_ordered, WM_groups[["all"]], by = "PTID")
temp_data$level <- factor(temp_data$level, levels = c("low", "med", "high"))

plot_data <- function(var){ 
  
  temp_data %>% 
    filter(!is.na(WMC)) %>% 
    group_by(WMC) %>% 
    summarise(variable = mean({{var}}, na.rm=TRUE), se_act = se({{var}}),se_min = variable-se_act, se_max = variable+se_act) %>%
    ggplot(aes(x=WMC, y = variable))+
    geom_bar(stat="identity")+
    geom_errorbar(aes(ymin=se_min, ymax=se_max), width=0.2)+
    ggtitle("EEG Capacity")+
    theme_classic()+
    scale_fill_discrete() -> EEG_plot
  
  temp_data %>% 
    filter(!is.na(level)) %>% 
    group_by(level) %>% 
    summarise(variable = mean({{var}}, na.rm=TRUE), se_act = se({{var}}),se_min = variable-se_act, se_max = variable+se_act) %>%
    ggplot(aes(x=level, y = variable))+
    geom_bar(stat="identity")+
    geom_errorbar(aes(ymin=se_min, ymax=se_max), width=0.2)+
    ggtitle("Omnibus Capacity")+
    theme_classic()+
    scale_fill_discrete() -> omnibus_plot
  
  groups_plot <- omnibus_plot + EEG_plot 
  
  return(groups_plot)
  
}

plot_data(FAC1_RT_TaskPerf_EEGonly) + plot_annotation(title="FAC1_RT_TaskPerf_EEGonly")
## `summarise()` ungrouping output (override with `.groups` argument)
## `summarise()` ungrouping output (override with `.groups` argument)

plot_data(Update_Alpha_FAC1) + plot_annotation(title="Update_Alpha_FAC1")
## `summarise()` ungrouping output (override with `.groups` argument)
## `summarise()` ungrouping output (override with `.groups` argument)

plot_data(Update_P3_FAC1) + plot_annotation(title="Update_P3_FAC1")
## `summarise()` ungrouping output (override with `.groups` argument)
## `summarise()` ungrouping output (override with `.groups` argument)

plot_data(Storage_gamma_FAC3_DFR) + plot_annotation(title="Storage_gamma_FAC3_DFR")
## `summarise()` ungrouping output (override with `.groups` argument)
## `summarise()` ungrouping output (override with `.groups` argument)

plot_data(Storage_LCD_CDA) + plot_annotation(title="Storage_LCD_CDA")
## `summarise()` ungrouping output (override with `.groups` argument)
## `summarise()` ungrouping output (override with `.groups` argument)

plot_data(Storage_DFR_n170) + plot_annotation(title="Storage_DFR_n170")
## `summarise()` ungrouping output (override with `.groups` argument)
## `summarise()` ungrouping output (override with `.groups` argument)

plot_data(Main_DPX_CNV_FCz_ACues) + plot_annotation(title="Main_DPX_CNV_FCz_ACues")
## `summarise()` ungrouping output (override with `.groups` argument)
## `summarise()` ungrouping output (override with `.groups` argument)

plot_data(Alerting_SCAP_P2fixn_Fz_allloads) + plot_annotation(title="Alerting_SCAP_P2fixn_Fz_allloads")
## `summarise()` ungrouping output (override with `.groups` argument)
## `summarise()` ungrouping output (override with `.groups` argument)

plot_data(LTM_theta_FAC1) + plot_annotation(title="LTM_theta_FAC1")
## `summarise()` ungrouping output (override with `.groups` argument)
## `summarise()` ungrouping output (override with `.groups` argument)

summary(aov(Storage_DFR_n170~level, data = temp_data))
##              Df Sum Sq Mean Sq F value Pr(>F)
## level         2   25.1   12.53   0.887  0.414
## Residuals   163 2302.8   14.13               
## 2 observations deleted due to missingness

When we remove boundary cases, we still see 46 subjects changing groups. The patterns match much better.

temp_data <- merge(constructs_fMRI, PC_ordered, by = "PTID")
temp_data <- merge(temp_data, p200_delay_avgs, by = "PTID")
temp_data <- temp_data[order(temp_data$omnibus_span_no_DFR),]
temp_data$level <- "low" 
temp_data$level[c(52:67,120:135)] <- NA
temp_data$level[68:119] <- "med"
temp_data$level[136:170] <- "high"
temp_data <- temp_data[order(temp_data$FAC2_Capacity_TaskPerf_EEGOnly),]
temp_data$WMC[c(52:67,120:135)] <- NA

temp_data$level <- factor(temp_data$level, levels = c("low", "med", "high"))

sum(temp_data$level != temp_data$WMC, na.rm=TRUE)
## [1] 46
plot_data <- function(var){ 
  
  temp_data %>% 
    filter(!is.na(WMC)) %>% 
    group_by(WMC) %>% 
    summarise(variable = mean({{var}}, na.rm=TRUE), se_act = se({{var}}),se_min = variable-se_act, se_max = variable+se_act) %>%
    ggplot(aes(x=WMC, y = variable))+
    geom_bar(stat="identity")+
    geom_errorbar(aes(ymin=se_min, ymax=se_max), width=0.2)+
    ggtitle("EEG Capacity")+
    theme_classic()+
    scale_fill_discrete() -> EEG_plot
  
  temp_data %>% 
    filter(!is.na(level)) %>% 
    group_by(level) %>% 
    summarise(variable = mean({{var}}, na.rm=TRUE), se_act = se({{var}}),se_min = variable-se_act, se_max = variable+se_act) %>%
    ggplot(aes(x=level, y = variable))+
    geom_bar(stat="identity")+
    geom_errorbar(aes(ymin=se_min, ymax=se_max), width=0.2)+
    ggtitle("Omnibus Capacity")+
    theme_classic()+
    scale_fill_discrete() -> omnibus_plot
  
  groups_plot <- omnibus_plot + EEG_plot 
  
  return(groups_plot)
  
}

plot_data(DFR) + plot_annotation(title = "DFR Delay activity")
## `summarise()` ungrouping output (override with `.groups` argument)
## `summarise()` ungrouping output (override with `.groups` argument)

plot_data(FAC1_RT_TaskPerf_EEGonly) + plot_annotation(title="FAC1_RT_TaskPerf_EEGonly")
## `summarise()` ungrouping output (override with `.groups` argument)
## `summarise()` ungrouping output (override with `.groups` argument)

plot_data(Update_Alpha_FAC1) + plot_annotation(title="Update_Alpha_FAC1")
## `summarise()` ungrouping output (override with `.groups` argument)
## `summarise()` ungrouping output (override with `.groups` argument)

plot_data(Update_P3_FAC1) + plot_annotation(title="Update_P3_FAC1")
## `summarise()` ungrouping output (override with `.groups` argument)
## `summarise()` ungrouping output (override with `.groups` argument)

plot_data(Storage_gamma_FAC3_DFR) + plot_annotation(title="Storage_gamma_FAC3_DFR")
## `summarise()` ungrouping output (override with `.groups` argument)
## `summarise()` ungrouping output (override with `.groups` argument)

plot_data(Storage_LCD_CDA) + plot_annotation(title="Storage_LCD_CDA")
## `summarise()` ungrouping output (override with `.groups` argument)
## `summarise()` ungrouping output (override with `.groups` argument)

plot_data(Storage_DFR_n170) + plot_annotation(title="Storage_DFR_n170")
## `summarise()` ungrouping output (override with `.groups` argument)
## `summarise()` ungrouping output (override with `.groups` argument)

plot_data(Main_DPX_CNV_FCz_ACues) + plot_annotation(title="Main_DPX_CNV_FCz_ACues")
## `summarise()` ungrouping output (override with `.groups` argument)
## `summarise()` ungrouping output (override with `.groups` argument)

plot_data(Alerting_SCAP_P2fixn_Fz_allloads) + plot_annotation(title="Alerting_SCAP_P2fixn_Fz_allloads")
## `summarise()` ungrouping output (override with `.groups` argument)
## `summarise()` ungrouping output (override with `.groups` argument)

plot_data(LTM_theta_FAC1) + plot_annotation(title="LTM_theta_FAC1")
## `summarise()` ungrouping output (override with `.groups` argument)
## `summarise()` ungrouping output (override with `.groups` argument)